Skip to content

Commit 71a9549

Browse files
committed
deploy: 2cc1344
1 parent 6f5a3d6 commit 71a9549

File tree

176 files changed

+31688
-907
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+31688
-907
lines changed

LiveDevelopment/LiveDevelopment.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,8 +1353,7 @@ define(function LiveDevelopment(require, exports, module) {
13531353
Metrics.countEvent(
13541354
Metrics.EVENT_TYPE.LIVE_PREVIEW,
13551355
"Open",
1356-
"usage",
1357-
1
1356+
"usage"
13581357
);
13591358

13601359
// Register user defined server provider and keep handlers for further clean-up

assets/default-project/en.zip

0 Bytes
Binary file not shown.

assets/new-project/assets/css/style.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ img {
271271
background: #292b2b;
272272
}
273273

274+
.project-card-active {
275+
background: #292b2b;
276+
}
277+
274278
.project-list {
275279
display: flex;
276280
justify-content: space-between;
@@ -862,6 +866,10 @@ img {
862866
border: 1px solid #016DC4;
863867
}
864868

869+
.error-border {
870+
border-color: red !important;
871+
}
872+
865873
.website-detail {
866874
margin-bottom: 15px;
867875
}
@@ -969,3 +977,7 @@ img {
969977
height: calc(100% - 50px);
970978
padding: 0px 15px 15px;
971979
}
980+
981+
.forced-hidden {
982+
display: none !important;
983+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14+
* for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
18+
*
19+
*/
20+
21+
/*global path, newProjectExtension, recentProjectExtension, Strings, Metrics*/
22+
/*eslint no-console: 0*/
23+
/*eslint strict: ["error", "global"]*/
24+
/* jshint ignore:start */
25+
26+
function _createRecentProjectCard(projectName, fullPath, nodeId, tabIndex) {
27+
let removeBtnDisableStyle = "";
28+
if(path.normalize(fullPath) === path.normalize(newProjectExtension.getWelcomeProjectPath())){
29+
removeBtnDisableStyle = "display: none;";
30+
}
31+
return $(`<li>
32+
<a id="${nodeId}" href="#"
33+
class="d-flex align-items-center justify-content-between tabable"
34+
tabindex="${tabIndex}"
35+
onclick="openProject('${fullPath}');_recentProjectMetric('open');">
36+
<div class="project-name">
37+
${projectName}
38+
</div>
39+
<button class="remove-btn" onclick="removeProject('${fullPath}');_recentProjectMetric('remove');"
40+
style="${removeBtnDisableStyle}">
41+
<svg width="16" height="16" viewBox="0 0 14 14" fill="none"
42+
xmlns="http://www.w3.org/2000/svg">
43+
<path d="M1.75 3.5H2.91667H12.25" stroke="#D0D0D0" stroke-linecap="round"
44+
stroke-linejoin="round"/>
45+
<path d="M4.6665 3.50008V2.33341C4.6665 2.024 4.78942 1.72725 5.00821 1.50846C5.22701 1.28966 5.52375 1.16675 5.83317 1.16675H8.1665C8.47592 1.16675 8.77267 1.28966 8.99146 1.50846C9.21026 1.72725 9.33317 2.024 9.33317 2.33341V3.50008M11.0832 3.50008V11.6667C11.0832 11.9762 10.9603 12.2729 10.7415 12.4917C10.5227 12.7105 10.2259 12.8334 9.91651 12.8334H4.08317C3.77375 12.8334 3.47701 12.7105 3.25821 12.4917C3.03942 12.2729 2.9165 11.9762 2.9165 11.6667V3.50008H11.0832Z"
46+
stroke="#D0D0D0" stroke-linecap="round" stroke-linejoin="round"/>
47+
<path d="M5.8335 6.41675V9.91675" stroke="#D0D0D0" stroke-linecap="round"
48+
stroke-linejoin="round"/>
49+
<path d="M8.1665 6.41675V9.91675" stroke="#D0D0D0" stroke-linecap="round"
50+
stroke-linejoin="round"/>
51+
</svg>
52+
</button>
53+
</a>
54+
</li>`);
55+
}
56+
57+
function _recentProjectMetric(type) {
58+
Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "recentProject.btnClick", type);
59+
}
60+
61+
function getDisplayName(projectPath) {
62+
const prefixRemove = [newProjectExtension.getLocalProjectsPath(), newProjectExtension.getMountDir()];
63+
for(let prefix of prefixRemove){
64+
if(projectPath.startsWith(prefix)){
65+
return projectPath.replace(prefix, '');
66+
}
67+
}
68+
return projectPath;
69+
}
70+
71+
function _updateProjectCards() {
72+
let recentProjectList = $(document.getElementById('recentProjectList'));
73+
recentProjectList.empty();
74+
let recentProjects = recentProjectExtension.getRecentProjects();
75+
let tabIndex = 20;
76+
for(let recentProject of recentProjects){
77+
recentProjectList.append(_createRecentProjectCard(getDisplayName(recentProject),
78+
recentProject, `recent-prj-list-${tabIndex}`, tabIndex++));
79+
}
80+
}
81+
82+
function openProject(fullPath) {
83+
recentProjectExtension.openProjectWithPath(fullPath)
84+
.then(()=>{
85+
newProjectExtension.closeDialogue();
86+
})
87+
.catch(()=>{
88+
_updateProjectCards();
89+
});
90+
}
91+
92+
function removeProject(fullPath) {
93+
recentProjectExtension.removeFromRecentProject(fullPath);
94+
_updateProjectCards();
95+
event.stopPropagation();
96+
}
97+
98+
function getPhoenixAbsURL(relativePath) {
99+
return `${window.parent.Phoenix.baseURL}${relativePath}`;
100+
}
101+
102+
function newProject(url, suggestedProjectName, title, license, licenseURL, credits, creditsURL) {
103+
let href = `new-project-from-url.html?url=${url}&suggestedName=${suggestedProjectName}&title=${title}`;
104+
if(license){
105+
href=`${href}&license=${license}`;
106+
}
107+
if(licenseURL){
108+
href=`${href}&licenseURL=${licenseURL}`;
109+
}
110+
if(credits){
111+
href=`${href}&credits=${credits}`;
112+
}
113+
if(creditsURL){
114+
href=`${href}&creditsURL=${creditsURL}`;
115+
}
116+
window.location.href = href;
117+
}
118+
119+
function initCodeEditor() {
120+
document.getElementById("openFolderBtn").onclick = function() {
121+
newProjectExtension.openFolder();
122+
Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "mainPage.btnClick", "open-folder");
123+
};
124+
document.getElementById("newGitHubProject").onclick = function() {
125+
window.location.href = 'new-project-github.html';
126+
Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "mainPage.btnClick", "github-project");
127+
};
128+
document.getElementById("exploreBtn").onclick = function() {
129+
openProject(newProjectExtension.getExploreProjectPath());
130+
Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "mainPage.btnClick", "explore");
131+
};
132+
document.getElementById("newBootstrapBlogBtn").onclick = function() {
133+
newProject(getPhoenixAbsURL("assets/sample-projects/bootstrap-blog.zip"),
134+
"bootstrap-blog", Strings.NEW_BOOTSTRAP_BLOG,
135+
"MIT", "https://github.com/twbs/bootstrap/blob/main/LICENSE",
136+
"https://getbootstrap.com", "https://getbootstrap.com");
137+
Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "mainPage.btnClick", "bootstrap-blog");
138+
};
139+
document.getElementById("newHTMLBtn").onclick = function() {
140+
newProject(getPhoenixAbsURL("assets/sample-projects/HTML5.zip"),
141+
"html project", Strings.NEW_HTML);
142+
Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "mainPage.btnClick", "html5");
143+
};
144+
_updateProjectCards();
145+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14+
* for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
18+
*
19+
*/
20+
21+
/*global newProjectExtension, Strings, Metrics*/
22+
/*eslint no-console: 0*/
23+
/*eslint strict: ["error", "global"]*/
24+
/* jshint ignore:start */
25+
26+
let createProjectBtn, websiteURLInput, locationInput;
27+
const FLATTEN_ZIP_FIRST_LEVEL_DIR = true;
28+
29+
function _isValidGitHubURL(url) {
30+
// strip trailing slash
31+
url = url.replace(/\/$/, "");
32+
let githubPrefix = "https://github.com/";
33+
let components = url.replace("https://github.com/", '').split('/');
34+
if(!url.startsWith(githubPrefix) || components.length !== 2){
35+
return false;
36+
}
37+
return true;
38+
}
39+
40+
function _fixGitHubBrokenURL() {
41+
let githubPrefix = "https://github.com/";
42+
let githubURL = websiteURLInput.value;
43+
if(githubURL.startsWith("http:")){
44+
githubURL = githubURL.replace("http:", "https:");
45+
}
46+
if(!githubURL.startsWith(githubPrefix)){
47+
return;
48+
}
49+
// strip any query string params if present
50+
let queryParamTrimIndex = githubURL.indexOf('?') >= 0 ? githubURL.indexOf('?') : githubURL.length;
51+
githubURL = githubURL.substring(0, queryParamTrimIndex);
52+
// trim everything after https://github.com/orgname/repo/... to https://github.com/orgname/repo
53+
let components = githubURL.replace("https://github.com/", '').split('/');
54+
if(components.length > 2){
55+
githubURL = `https://github.com/${components[0]}/${components[1]}`;
56+
}
57+
websiteURLInput.value = githubURL;
58+
}
59+
60+
function _validateGitHubURL() {
61+
_fixGitHubBrokenURL();
62+
let githubURL = websiteURLInput.value;
63+
if(_isValidGitHubURL(githubURL)){
64+
$(websiteURLInput).removeClass("error-border");
65+
return true;
66+
}
67+
$(websiteURLInput).addClass("error-border");
68+
return false;
69+
}
70+
71+
function _validateProjectLocation() {
72+
if(!window.showDirectoryPicker){
73+
// fs access apis not present, so we will give phoenix empty location to figure out a suitable location
74+
return true;
75+
}
76+
let location = locationInput.value;
77+
if( location === Strings.PLEASE_SELECT_A_FOLDER){
78+
$(locationInput).addClass("error-border");
79+
return false;
80+
}
81+
$(locationInput).removeClass("error-border");
82+
return true;
83+
}
84+
85+
function _validate() {
86+
return _validateGitHubURL()
87+
&& _validateProjectLocation();
88+
}
89+
90+
function _selectFolder() {
91+
newProjectExtension.showFolderSelect()
92+
.then(file =>{
93+
locationInput.fullPath = file;
94+
locationInput.value = file.replace(newProjectExtension.getMountDir(), "");
95+
_validateProjectLocation();
96+
});
97+
}
98+
99+
function _createProjectClicked() {
100+
if(_validate()){
101+
let githubURL = websiteURLInput.value;
102+
let components = githubURL.replace("https://github.com/", '').split('/');
103+
let zipURL = `https://phcode.site/getGitHubZip?org=${components[0]}&repo=${components[1]}`;
104+
let suggestedProjectName = `${components[0]}-${components[1]}`;
105+
newProjectExtension.downloadAndOpenProject(
106+
zipURL,
107+
locationInput.fullPath, suggestedProjectName, FLATTEN_ZIP_FIRST_LEVEL_DIR)
108+
.then(()=>{
109+
Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "github.btnClick", "create.success");
110+
newProjectExtension.closeDialogue();
111+
});
112+
} else {
113+
newProjectExtension.showErrorDialogue(
114+
Strings.MISSING_FIELDS,
115+
Strings.PLEASE_FILL_ALL_REQUIRED);
116+
}
117+
Metrics.countEvent(Metrics.EVENT_TYPE.NEW_PROJECT, "github.btnClick", "create");
118+
}
119+
120+
function initGithubProject() {
121+
if(!window.showDirectoryPicker){ // fs access apis not present
122+
$(document.getElementById("projectLocation")).addClass("forced-hidden");
123+
}
124+
createProjectBtn = document.getElementById("createProjectBtn");
125+
websiteURLInput = document.getElementById("websiteURLInput");
126+
locationInput = document.getElementById("locationInput");
127+
createProjectBtn.onclick = _createProjectClicked;
128+
$(websiteURLInput).keyup(_validate);
129+
locationInput.value = Strings.PLEASE_SELECT_A_FOLDER;
130+
locationInput.onclick = _selectFolder;
131+
_validate();
132+
}

0 commit comments

Comments
 (0)