Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Detect when file was changed and asks to be saved
Browse files Browse the repository at this point in the history
Now whenever the file changes the save icon will be shown as enabled and
it will put a * char in front of the filename.

If the file was changed and the page is closed, it will show a dialog asking to
warning that the file was changed and it may be saved.

This patch also fixes some syntaxes issues.

Signed-off-by: Bruno Bottazzini <bruno.bottazzini@intel.com>
  • Loading branch information
Bruno Bottazzini committed Oct 16, 2015
1 parent eed8984 commit 99dd1b4
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 40 deletions.
22 changes: 22 additions & 0 deletions client/css/app.css
Expand Up @@ -259,6 +259,28 @@ iframe{
outline: 0;
}

.button_save_on {
background:url(../imgs/button_save_en.png);
background-repeat: no-repeat;
width:41px;
height:45px;
border: 0;
position: relative;
bottom: -17;
outline: 0;
}

.button_save_off {
background:url(../imgs/button_save_dis.png);
background-repeat: no-repeat;
width:41px;
height:45px;
border: 0;
position: relative;
bottom: -17;
outline: 0;
}

.button_login_on {
background:url(../imgs/login_on.png);
background-repeat: no-repeat;
Expand Down
Binary file added client/imgs/button_save_dis.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 79 additions & 40 deletions client/js/controllers/editor.js
Expand Up @@ -48,6 +48,7 @@
$scope.runConf = false;
$scope.loginConf = false;
$scope.runJournal = false;
$scope.shouldSave = false;
svConf.fetchConf().success(function(data){
$scope.runConf = data.run_fbp_access;
$scope.loginConf = data.login_system;
Expand Down Expand Up @@ -79,6 +80,7 @@
editor.session.setOption("useWorker", false);
editor.setFontSize(15);
editor.setTheme('ace/theme/monokai');
editor.keyBinding.origOnTextInput = editor.keyBinding.onTextInput;

$scope.fbpType = true;
aceConfig.set("modePath", "js/ace/");
Expand All @@ -93,22 +95,20 @@
$scope.owner = rfinal[1];
$scope.repo = rfinal[2];
$scope.getConfigurationlist(_l.id);
if (filePath && isLeaf) {
$scope.saveFile(filePath, editor.getSession().getValue());//Saving previous file
}
isLeaf = _l.isLeaf;
filePath = _l.id;
aceConfig.set("modePath", "libs/ace-builds/src-min/");
$scope.fileName = ': ' + filePath.split("/").pop(); //getting the selected node name
if (_l.isLeaf) {
FetchFileFactory.fetchFile(_l.base).then(function(data) {
var _d = data.data;
var previousContent = editor.getSession().getValue();
if (typeof _d == 'object') {
_d = JSON.stringify(_d, undefined, 2);
}
$scope.setEditorContent(_d, previousContent, filePath);
filePath = _l.id;
$scope.fileName = ': ' + filePath.split("/").pop(); //getting the selected node name
var mode = modelist.getModeForPath(filePath).mode;
editor.session.setMode(mode);
editor.getSession().setValue(_d);
var type_file = _l.base.slice(-3);
if (type_file === "fbp") {
$scope.fbpType = true;
Expand All @@ -127,18 +127,20 @@
});
$scope.root = false;
} else {
filePath = _l.id;
$scope.fileName = ': ' + filePath.split("/").pop(); //getting the selected node name
editor.setReadOnly(true);
editor.setHighlightActiveLine(false);
if (data.node.parent === "#") {
$scope.root = true;
editor.getSession().setValue('Please select a file to view its contents');
$scope.setEditorContent('Please select a file to view its contents', null, null);
} else {
if (data.node.parents[1] === "#") {
$scope.root = true;
editor.getSession().setValue('Please select a file to view its contents');
$scope.setEditorContent('Please select a file to view its contents', null, null);
} else {
if (!isLeaf) {
editor.getSession().setValue('Please select a file to view its contents');
$scope.setEditorContent('Please select a file to view its contents', null, null);
}
$scope.root = false;
}
Expand All @@ -161,6 +163,23 @@
}
}

$scope.setEditorContent = function (content, previousContent, savePath) {
if ($scope.shouldSave === false || !previousContent) {
editor.getSession().setValue(content);
} else {
sure_dialog("Save", "The file was changed. Would you like to save it?",
function(close_id) {
if(close_id) {
$scope.saveFile(savePath, previousContent);
editor.getSession().setValue(content);
} else {
editor.getSession().setValue(content);
}
});
$scope.shouldSave = false;
}
};

$scope.getConfigurationlist = function (repo_id) {
if ($scope.owner && $scope.repo) {
var id = "/";
Expand Down Expand Up @@ -239,7 +258,7 @@
promiseRunViewer = $interval(function () { $scope.getOutput(); }, $scope.runDialogRefreshPeriod);
};

$scope.getOutput = function () {
$scope.getOutput = function () {
$http.get('/api/journald',
{
params: {
Expand Down Expand Up @@ -278,9 +297,6 @@
} else {
alert("FBP Failed to run");
}
if (filePath) {
$scope.saveFile(filePath, editor.getSession().getValue());
}
}).error(function(){
$scope.openRunDialog();
});
Expand Down Expand Up @@ -395,24 +411,19 @@
diag.dialog("open");
};

window.addEventListener("beforeunload", function (e) {
if (filePath) {
var repo = filePath.split("repos/")[1].split("/")[0];
if (repo !== "solettaproject") {
//Saving previous file
$scope.saveFile(filePath, editor.getSession().getValue());
window.onbeforeunload = onBeforeUnload_Handler;
function onBeforeUnload_Handler(){
$http.post('/api/fbp/stop').success(function(data) {
if (data == 1) {
alert("FBP Service failed to stop. Process should be stopped manually");
}
});
if ($scope.shouldSave === true) {
return "The file was changed and the data was not saved.";
} else {
return undefined;
}

if ($scope.isServiceRunning) {
$http.post('/api/fbp/stop').success(function(data) {
if (data == 1) {
alert("FBP Service failed to stop. Process should be stopped manually");
}
});
}
});

}

$scope.checkSyntax = function () {
var fbpCode = editor.getSession().getValue();
Expand Down Expand Up @@ -483,21 +494,49 @@

$scope.saveFile = function(path, body) {
if (body && path && isLeaf) {
var repo = path.split("repos/")[1].split("/")[0];
if (repo !== "solettaproject") {
$http.get('api/file/write',
{params: {
"file_path": path,
"file_body": body
}
});
}
$http.get('api/file/write',
{params: {
"file_path": path,
"file_body": body
}
});
}
};

$scope.saveFileManually = function() {
if ($scope.shouldSave) {
var file = filePath;
var body = editor.getSession().getValue();
if (file && body) {
$http.get('api/file/write',
{params: {
"file_path": file,
"file_body": body
}
}).success(function(data) {
$scope.shouldSave = false;
//pop * from the string
$scope.fileName = $scope.fileName.substring(0, $scope.fileName.length-1);
}).error(function(){
alert("Failed to save file on server. Try again.");
$scope.shouldSave = true;
});
} else {
alert("Something went terrbile wrong.\nFailed to save file on server. Try again.");
}
}
};


editor.keyBinding.onTextInput = function(text) {
if ($scope.shouldSave === false && $scope.fileName) {
$scope.fileName = $scope.fileName + "*";
$scope.shouldSave = true;
}
this.origOnTextInput(text);
};

$scope.editorChanged = function (e) {
// Lets put some interfaces like * that will warn user
//the file has changed
if (isRunningSyntax === false) {
isRunningSyntax = true;
$scope.checkSyntaxStart();
Expand Down
1 change: 1 addition & 0 deletions server/views/index.html
Expand Up @@ -129,6 +129,7 @@
<input type="text" ng-model="repoUrl" placeholder="Git repository URL" style="outline: 0; width: 320px; margin-right: -2px;" class="inputControls" />
<button type="submit" style="outline: 0; margin-left: -11px;" title="Sync repository git" tabindex="0" id="syncGit" ng-click="syncGit()" ng-disabled="buttonSyncDisabled"/><img src="imgs/button_sync.png"></button>
<!--<button type="button" title="Commit" style="outline: 0; margin-left: -11px;" id="commitGit" ng-click="commitDiag()" ng-disabled="buttonSyncDisabled" href="#"><img src="imgs/button_commit.png"></button>-->
<button type="button" ng-class="{'button_save_on': shouldSave == true, 'button_save_off': shouldSave == false}" ng-click="saveFileManually()" title="Save current file"></button>
<button type="button" ng-class="{'button_lib_on': libChecked == true, 'button_lib_off': libChecked == false}" ng-click="libChecked = !libChecked" title="Collapse projects panel"></button>
<button type="button" ng-class="{'button_code_on': codeChecked == true, 'button_code_off': codeChecked == false}" ng-click="codeChecked = !codeChecked" title="Collapse code panel" ></button>
<button type="button" style="margin-right: 5px;" ng-class="{'button_svg_on': svgChecked == true, 'button_svg_off': svgChecked == false}" ng-click="svgChecked = !svgChecked" title="Collapse SVG panel"></button>
Expand Down

0 comments on commit 99dd1b4

Please sign in to comment.