Skip to content

Commit

Permalink
versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Giona Righini committed Oct 18, 2019
1 parent 123b592 commit 496c469
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 35 deletions.
8 changes: 0 additions & 8 deletions Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,7 @@ sap.ui.define([
// set the i18n model
this.setModel(models.createResourceModel(mConfig.i18nBundle), "i18n");
// call the base component's init function
var headers = {
"Access-Control-Allow-Origin": "*"
};
jQuery.sap.require("jquery.sap.storage");
var oStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);
var mUser = oStorage.get("myUser");
var mToken = oStorage.get("myToken");
//sap.m.MessageToast.show(mUser + " - " + mPwd);
var sServiceUrl = mConfig.serviceConfig.serviceUrl;

sap.ui.getCore().getConfiguration().setLanguage("en");

Expand Down
7 changes: 3 additions & 4 deletions application.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
oApplication = { // Application is an object
load: function (src, id, libs, theme, callback) {
var that = this;
setTimeout(function () {
that.loadSAPUI5(src, id, libs, theme, callback);
setTimeout(() => {
this.loadSAPUI5(src, id, libs, theme, callback);
}, 0);
},
loadSAPUI5: function (src, id, libs, theme, callback) {
Expand Down Expand Up @@ -43,7 +42,7 @@ oApplication = { // Application is an object
app: new sap.ui.core.ComponentContainer({
height: "100%",
name: "Wstat",
componentCreated: function () { }
componentCreated: function () {}
})
});
});
Expand Down
27 changes: 19 additions & 8 deletions controller/BaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ sap.ui.define([
Del = 1;
}
if (Mode == 2) {
detail = () => {
detail = updated => {
Model.oData.detail.updated = updated
Model.setProperty("/detailRTF", Model.oData.detail);
Model.setProperty("/detailDB", Object.assign({}, Model.oData.detail));
Model.setProperty("/saved");
Expand All @@ -157,10 +158,19 @@ sap.ui.define([
});
};
}
this.saveDay(mVal, mNote, Model.oData.detail.DATE, Del, detail);
var check = http => {
if (http.status == 200) {
if (jQuery.isFunction(detail)) {
detail(http.response.replace(/(\r\n|\n|\r)/gm, ""))
}
} else {
this.onError("MyDailyNotes", "È presente un conflitto di versione, aggiornare il calendario")
}
}
this.saveDay(mVal, mNote, Model.oData.detail.DATE, Del, Model.oData.detail.updated, check);
dialog.close();
},
saveDay: function (Val, Note, Date, Del, Callback) {
saveDay: function (Val, Note, Date, Del, Updated, Callback) {
jQuery.sap.require("jquery.sap.storage");
var oStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);
var mUser = oStorage.get("myUser");
Expand All @@ -174,20 +184,21 @@ sap.ui.define([
date: Date,
val: Val,
note: Note,
del: Del
del: Del,
timestamp: Updated
}
let req = JSON.stringify(params);
http.open('POST', url, true);
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.onreadystatechange = () => {
if (http.readyState == 4) {
if (http.status == 200) {
if (http.status == 200) { //accettato
if (jQuery.isFunction(this.onSelect)) {
this.onSelect(Date);
}
if (jQuery.isFunction(Callback)) {
Callback();
}
Callback(http)
} else if (http.status == 205) { //non accettato, conflitto con salvataggio
Callback(http)
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions controller/Main.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ sap.ui.define([
"val": 1,
"note": ""
};
} else if (!jDetail[0].active) {
jDetail[0].val = 1
jDetail[0].note = ""
}
oModel.setProperty("/detail", Object.assign({}, jDetail[0]));
//Popup
Expand Down
38 changes: 23 additions & 15 deletions controller/Slave.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ sap.ui.define([
},
checkChange: function (oEvent) {
var oModel = this.getOwnerComponent().getModel("global");
var that = this;
if (oModel.getProperty("/detailRTF").note != oModel.getProperty("/detailDB").note) {
that.save();
setTimeout(() => {
this.save()
}, 1000)
}
},
onDelete: function (oEvent) {
var that = this;
this.onConfirm("Delete item?", function () {
that.onExit(1);
this.onConfirm("Delete item?", () => {
this.onExit(1);
});
},
onCode: function (oEvent) {
Expand All @@ -94,8 +94,14 @@ sap.ui.define([
var oModel = this.getOwnerComponent().getModel("global");
var rtf = oModel.getProperty("/detailRTF");
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
this.saveDay(rtf.val, rtf.note, rtf.DATE, Del, function () {
oRouter.navTo("main", true);
this.saveDay(rtf.val, rtf.note, rtf.DATE, Del, rtf.updated, http => {
if (http.status == 200) {
oRouter.navTo("main", true);
} else {
this.onConfirm("È presente un conflitto di versione, ricaricare il calendario? (Si perderanno queste ultime modifiche)", () =>{
oRouter.navTo("main", true);
})
}
});
},
handleRouteMatched: function (oEvent) {
Expand All @@ -107,14 +113,16 @@ sap.ui.define([
save: function (oEvent) {
var oModel = this.getOwnerComponent().getModel("global");
var rtf = oModel.getProperty("/detailRTF");
var that = this;
this.saveDay(rtf.val, rtf.note, rtf.DATE, 0, function () {
oModel.setProperty("/detailDB", Object.assign({}, rtf));
var now = new Date().toLocaleTimeString([], {
hour: 'numeric',
minute: '2-digit'
});
oModel.setProperty("/saved", now);
this.saveDay(rtf.val, rtf.note, rtf.DATE, 0, rtf.updated, http => {
if (http.status == 200) {
rtf.updated = http.response.replace(/(\r\n|\n|\r)/gm, "");
oModel.setProperty("/detailDB", Object.assign({}, rtf));
var now = new Date().toLocaleTimeString([], {
hour: 'numeric',
minute: '2-digit'
});
oModel.setProperty("/saved", now);
}
});
}
});
Expand Down

0 comments on commit 496c469

Please sign in to comment.