Skip to content

Commit 5bba8ab

Browse files
committed
Added option to rename project
1 parent e726f93 commit 5bba8ab

File tree

3 files changed

+79
-22
lines changed

3 files changed

+79
-22
lines changed

anyoneai/static/css/index.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ html, body, #fullheight {
44
height: 100%;
55
font-family: "Open Sans", "Roboto", sans-serif !important;
66
background-color: #fafafa !important;
7-
87
}
98

109
body {

anyoneai/static/js/index.js

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,48 @@ function get_files() {
3939
}
4040

4141
function newProject() {
42-
window.open("../build?a=new");
42+
$('#startLabModal').modal('show')
43+
document.getElementById("file_Exists_indicator").style.display = "none";
44+
document.getElementById("prj_filename").value = "Untitled Project";
45+
46+
// window.open("../build?a=new");
47+
}
48+
49+
function createProject(){
50+
var filename = document.getElementById("prj_filename");
51+
$.get('../service/build/create', {filename:filename.value}, function(data) {
52+
if(data == "file exists") {
53+
document.getElementById("file_Exists_indicator").style.display = "block";
54+
} else {
55+
$('#startLabModal').modal('hide')
56+
get_files();
57+
window.open("../build?filename=" + data);
58+
}
59+
}
60+
);
61+
62+
}
63+
64+
function rename_file(){
65+
var new_filename = document.getElementById("rename_filename");
66+
$.get('../service/build/rename', {filename:file_selected, new_filename:new_filename.value}, function (data, textStatus, jqXHR) {
67+
if(data == "done") {
68+
get_files();
69+
$('#renameModal').modal('hide');
70+
} else {
71+
document.getElementById("rename_error").style.display = "block";
72+
}
73+
});
4374
}
75+
76+
4477
var file_selected;
4578
window.addEventListener("contextmenu", e => {
46-
if(e.target.classList[0] == "c-card-file") {
47-
console.log(e.target.id);
79+
if(e.target.classList[0] == "c-card-file" || e.target.parentElement.classList[0] == "c-card-file") {
80+
if (e.target.classList[0] == "c-card-file")
4881
file_selected = e.target.id;
82+
else
83+
file_selected = e.target.parentElement.id;
4984
e.preventDefault();
5085
const origin = {
5186
left: e.pageX,
@@ -89,19 +124,18 @@ window.addEventListener("click", e => {
89124
if(e.target.innerHTML == "Open") {
90125
document.getElementById(file_selected).click();
91126
} else if (e.target.innerHTML == "Duplicate") {
92-
$.get('../service/build/duplicate', {file:file_selected}, function (data, textStatus, jqXHR) {
127+
$.get('../service/build/duplicate', {filename:file_selected}, function (data, textStatus, jqXHR) {
93128
if(data == "done") {
94129
get_files();
95130
}
96131
});
97132
} else if (e.target.innerHTML == "Rename") {
98-
$.get('../service/build/rename', {file:file_selected}, function (data, textStatus, jqXHR) {
99-
if(data == "done") {
100-
get_files();
101-
}
102-
});
133+
document.getElementById("rename_error").style.display = "none";
134+
document.getElementById("rename_filename").value = file_selected;
135+
$('#renameModal').modal('show');
136+
103137
} else if (e.target.innerHTML == "Delete"){
104-
$.get('../service/build/delete', {file:file_selected}, function (data, textStatus, jqXHR) {
138+
$.get('../service/build/delete', {filename:file_selected}, function (data, textStatus, jqXHR) {
105139
if(data == "done") {
106140
get_files(); }
107141
});

anyoneai/templates/index.html

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,51 @@
8686

8787
<div class="modal fade" id="startLabModal" tabindex="-1" role="dialog" aria-labelledby="Start Lab"
8888
aria-hidden="true">
89-
9089
<div class="modal-dialog modal-dialog-centered" role="document">
91-
92-
9390
<div class="modal-content" style="padding: 5px">
9491
<div class="modal-header">
95-
<h5 class="modal-title" id="exampleModalLongTitle" style="color: black; font-size: 22px;">Start lab?</h5>
92+
<h5 class="modal-title" id="exampleModalLongTitle" style="color: black; font-size: 22px;">New Project</h5>
93+
</div>
94+
<div class="modal-body" style="padding-bottom: 0px; padding-top: 0px;">
95+
<p>AnyoneAI projects will have (.aai) extention.</p>
96+
<div class="md-form md-outline">
97+
<input type="text" id="prj_filename" class="form-control" value="Untitled Project">
98+
<label for="form1">Project Name</label>
99+
<small id="file_Exists_indicator" class="form-text text-danger" style="display:none">A project with the same name already exists in the folder.</small>
100+
</div>
101+
<div class="modal-footer" style="padding-top: 0px; ">
102+
<button type="button" class="btn" data-dismiss="modal" style="color: black;">Cancel</button>
103+
<button type="button" class="btn btn-primary" onclick="createProject()">Create</button>
104+
</div>
105+
</div>
106+
</div>
107+
</div>
108+
</div>
96109

110+
<div class="modal fade" id="renameModal" tabindex="-1" role="dialog" aria-labelledby="Start Lab"
111+
aria-hidden="true">
112+
<div class="modal-dialog modal-dialog-centered" role="document">
113+
<div class="modal-content" style="padding: 5px">
114+
<div class="modal-header">
115+
<h5 class="modal-title" style="color: black; font-size: 22px;">Rename File</h5>
97116
</div>
98-
<div class="modal-body" style="padding-bottom: 0px">
99-
<h5 style="font-size: 16px; font-weight: 400; color: black">Instruction</h5>
100-
<p id="model_text" style="font-weight: 100; color: grey"></p>
101-
<h5 style="font-size: 16px; font-weight: 400; color: black">Duration</h5>
102-
<p style="font-weight: 100; color: grey">10 mins</p>
103-
<div class="modal-footer">
117+
<div class="modal-body" style="padding-bottom: 0px; padding-top: 0px;">
118+
<p>Enter the new file name.</p>
119+
<div class="md-form md-outline">
120+
<input type="text" id="rename_filename" class="form-control" value="Untitled Project">
121+
<label for="rename_filename">File Name</label>
122+
<small id="rename_error" class="form-text text-danger" style="display:none">Unable to rename file.</small>
123+
</div>
124+
<div class="modal-footer" style="padding-top: 0px; ">
104125
<button type="button" class="btn" data-dismiss="modal" style="color: black;">Cancel</button>
105-
<button type="button" class="btn btn-primary" onclick="window.open(lab_session_url()); $('#startLabModal').modal('hide');">Start</button>
126+
<button type="button" class="btn btn-primary" onclick="rename_file()">Rename</button>
106127
</div>
107128
</div>
108129
</div>
109130
</div>
131+
</div>
132+
133+
110134

111135
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
112136
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.4/umd/popper.min.js"></script>

0 commit comments

Comments
 (0)