adding RIBC operations
This commit is contained in:
parent
e7614d4ebf
commit
db992e65f8
494
RIBC.html
494
RIBC.html
@ -37,8 +37,10 @@
|
||||
</head>
|
||||
|
||||
<body onload="onLoadStartUp()">
|
||||
<div id="UI">
|
||||
RIBC
|
||||
(use console)
|
||||
</div>
|
||||
|
||||
<script id="init_lib">
|
||||
//All util libraries required for Standard operations (DO NOT EDIT ANY)
|
||||
@ -8714,8 +8716,500 @@ Bitcoin.Util = {
|
||||
floDapps.launchStartUp().then(result => {
|
||||
console.log(result)
|
||||
alert(`Welcome FLO_ID: ${myFloID}`)
|
||||
RIBC.initRIBC().then(result => {
|
||||
console.log(result)
|
||||
}).catch(error => console.error(error))
|
||||
}).catch(error => console.error(error))
|
||||
}
|
||||
</script>
|
||||
<script id="RIBC_operations">
|
||||
|
||||
const RIBC = {
|
||||
|
||||
initRIBC: function(){
|
||||
return new Promise((resolve, reject) => {
|
||||
Promise.all([this.refreshObjectData(), this.refreshGeneralData()])
|
||||
.then(results => resolve(results))
|
||||
.catch(error => reject(error))
|
||||
})
|
||||
},
|
||||
|
||||
refreshObjectData: function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
floCloudAPI.requestObjectData("RIBC").then(result => {
|
||||
this.manage.initAppObjects()
|
||||
resolve('Object Data Refreshed Successfully')
|
||||
}).catch(error => reject(error))
|
||||
})
|
||||
},
|
||||
|
||||
refreshGeneralData: function(){
|
||||
return new Promise((resolve, reject) => {
|
||||
var generalDataList = ["InternUpdates"]
|
||||
var promises = []
|
||||
Promise.all(generalDataList.map(data => floCloudAPI.requestGeneralData(data)))
|
||||
.then(results => resolve('General Data Refreshed Successfully'))
|
||||
.catch(error => reject(error))
|
||||
})
|
||||
},
|
||||
|
||||
postInternUpdate: function(updates){
|
||||
return new Promise((resolve, reject) => {
|
||||
floCloudAPI.sendGeneralData(updates, "InternUpdates")
|
||||
.then(results => resolve(results))
|
||||
.catch(error => reject(error))
|
||||
})
|
||||
},
|
||||
|
||||
getInternUpdates: function(count = null){
|
||||
var filterStr = floDapps.util.getFilterString("InternUpdates")
|
||||
var internUpdates = floGlobals.generalData[filterStr].map(data => {return {floID: data.sender, update: data.message}})
|
||||
internUpdates = internUpdates.filter(data => data.floID in floGlobals.appObjects.RIBC.internList)
|
||||
internUpdates.reverse()
|
||||
if(count && count < internUpdates.length)
|
||||
internUpdates = internUpdates.slice(0, count)
|
||||
return internUpdates
|
||||
},
|
||||
|
||||
getProjectList: () => {
|
||||
return Object.keys(floGlobals.appObjects.RIBC.projectMaps)
|
||||
},
|
||||
|
||||
getProjectDetails: (project) => {
|
||||
return floGlobals.appObjects.RIBC.projectDetails[project]
|
||||
},
|
||||
|
||||
getProjectMap: (project) => {
|
||||
return floGlobals.appObjects.RIBC.ProjectMap[project]
|
||||
},
|
||||
|
||||
getProjectBranches: (project) => {
|
||||
return this.manage.findAllBranches(project)
|
||||
},
|
||||
|
||||
getTaskDetails: (project, branch, task) => {
|
||||
return this.manage.readTaskDetails(project, branch, task)
|
||||
},
|
||||
|
||||
getTaskStatus: (project, branch, task) => {
|
||||
return this.manage.readTaskStatus(project, branch, task)
|
||||
},
|
||||
|
||||
getInternList: () => {
|
||||
return floGlobals.appObjects.RIBC.internList;
|
||||
},
|
||||
|
||||
getInternRating: (floID) => {
|
||||
return floGlobals.appObjects.RIBC.internRating[floID];
|
||||
},
|
||||
|
||||
getAssignedInterns: (projectCode, branch, taskNumber) => {
|
||||
return floGlobals.appObjects.RIBC.internsAssigned[projectCode + "_" + branch + "_" + taskNumber]
|
||||
},
|
||||
|
||||
manage: {
|
||||
|
||||
initAppObjects: function(){
|
||||
this.projectMap = floGlobals.appObjects.RIBC.projectMap;
|
||||
this.projectBranches = floGlobals.appObjects.RIBC.projectBranches;
|
||||
this.projectTaskDetails = floGlobals.appObjects.RIBC.projectTaskDetails;
|
||||
this.projectDetails = floGlobals.appObjects.RIBC.projectDetails;
|
||||
this.internList = floGlobals.appObjects.RIBC.internList;
|
||||
this.internRating = floGlobals.appObjects.RIBC.internRating;
|
||||
this.internsAssigned = floGlobals.appObjects.RIBC.internsAssigned;
|
||||
this.projectTaskStatus = floGlobals.appObjects.RIBC.projectTaskStatus;
|
||||
this.lastCommit = JSON.stringify(floGlobals.appObjects.RIBC);
|
||||
},
|
||||
|
||||
updateObjects: function(){
|
||||
return new Promise((resolve, reject) => {
|
||||
floCloudAPI.updateObjectData(JSON.parse(this.lastCommit), floGlobals.appObjects.RIBC,"RIBC").then(result => {
|
||||
this.lastCommit = JSON.stringify(floGlobals.appObjects.RIBC)
|
||||
resolve(result)
|
||||
}).catch(error => reject(error))
|
||||
})
|
||||
},
|
||||
|
||||
resetObjects: function(){
|
||||
return new Promise((resolve, reject) => {
|
||||
floCloudAPI.resetObjectData(floGlobals.appObjects.RIBC, "RIBC").then(result => {
|
||||
this.lastCommit = JSON.stringify(floGlobals.appObjects.RIBC)
|
||||
resolve(result)
|
||||
}).catch(error => reject(error))
|
||||
})
|
||||
},
|
||||
|
||||
addProjectDetails: function(projectCode, details){
|
||||
if(!(projectCode in this.projectMap))
|
||||
return "Project not Found!"
|
||||
this.projectDetails[projectCode] = details
|
||||
return "added project details for "+projectCode
|
||||
},
|
||||
|
||||
addIntern: function(floID, internName){
|
||||
if(floID in this.internList)
|
||||
return "floID already registered as Intern"
|
||||
this.internList[floID] = internName
|
||||
this.internRating[floID] = 1
|
||||
return "Intern Added: "+floID+": "+internName;
|
||||
},
|
||||
|
||||
updateInternRating: function(floID, change = 0){
|
||||
if(!(floID in this.internList))
|
||||
return "Intern not found!"
|
||||
this.internRating[floID] += change
|
||||
return "Intern rating Updated";
|
||||
},
|
||||
|
||||
assignInternToTask: function(floID, projectCode, branch, taskNumber){
|
||||
var index = projectCode + "_" + branch + "_" + taskNumber
|
||||
if(!Array.isArray(this.internsAssigned[index]))
|
||||
this.internsAssigned[index] = []
|
||||
if(!this.internsAssigned[index].includes(floID))
|
||||
this.internsAssigned[index].push(floID)
|
||||
},
|
||||
|
||||
unassignInternFromTask: function(floID, projectCode, branch, taskNumber){
|
||||
var index = projectCode + "_" + branch + "_" + taskNumber
|
||||
var pos = this.internsAssigned[index].indexOf(floID)
|
||||
if(pos > -1)
|
||||
this.internsAssigned[index].splice(pos, 1)
|
||||
},
|
||||
|
||||
readTaskStatus: function (projectCode, branch, taskNumber) {
|
||||
return this.projectTaskStatus[projectCode + "_" + branch + "_" + taskNumber];
|
||||
},
|
||||
|
||||
putTaskStatus: function (taskStatus, projectCode, branch, taskNumber) {
|
||||
//add taskDetails
|
||||
this.projectTaskStatus[projectCode + "_" + branch + "_" + taskNumber] = taskStatus;
|
||||
},
|
||||
|
||||
createProject: function (projectCode) {
|
||||
if (projectCode in this.projectMap) {
|
||||
return "Project Name already exists";
|
||||
}
|
||||
addBranch(projectCode);
|
||||
return "Project Create: " + projectCode
|
||||
},
|
||||
|
||||
copyBranchtoNewProject: function (oldProjectCode, oldBranch, newProjectCode, newBranchConnection,
|
||||
newStartPoint, newEndPoint) {
|
||||
//Make sure new branch is a new text string that does not exist in new project
|
||||
if (oldBranch == "mainLine") {
|
||||
return "You cannot change mainLine";
|
||||
}
|
||||
if (this.projectMap.hasOwnProperty(newProjectCode) == false) {
|
||||
return "The project does not exist"
|
||||
}
|
||||
if (this.projectMap[newProjectCode].hasOwnProperty(newBranch) == false) {
|
||||
return "The branch does not exist"
|
||||
}
|
||||
if (newStartPoint > newEndPoint) {
|
||||
return "Startpoint cannot be later than endpoint"
|
||||
}
|
||||
|
||||
var newBranch = addBranch(newProjectCode, newBranchConnection, newStartPoint, newEndPoint);
|
||||
this.projectMap[newProjectCode][newBranch] = this.projectMap[oldProjectCode][oldBranch].slice();
|
||||
|
||||
|
||||
if (newBranchConnection == "undefined") {
|
||||
this.projectMap[newProjectCode][newBranch][0] = "mainLine";
|
||||
} else {
|
||||
this.projectMap[newProjectCode][newBranch][0] = "newBranchConnection";
|
||||
}
|
||||
if (newStartPoint != "undefined") {
|
||||
this.projectMap[newProjectCode][newBranch][2] = newStartPoint;
|
||||
}
|
||||
if (newEndPoint != "undefined") {
|
||||
this.projectMap[newProjectCode][newBranch][3] = newEndPoint;
|
||||
}
|
||||
|
||||
//Add entry in this.projectBranches.This may not be needed now
|
||||
//this.projectBranches[newProjectCode] = this.projectBranches[newProjectCode]+","+newBranch;
|
||||
|
||||
//Copy Task List too
|
||||
var p = this.projectTaskDetails;
|
||||
for (var key in p) {
|
||||
if (p.hasOwnProperty(key)) {
|
||||
if (key.contains(oldProjectCode + "_" + oldBranch)) {
|
||||
var numberExtract = key.replace(oldProjectCode + "_" + oldBranch + "_", "");
|
||||
this.projectTaskDetails[newProjectCode + "_" + newBranch + "_" + numberExtract] = p[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.projectMap[newProjectCode][newBranch];
|
||||
},
|
||||
|
||||
deleteTaskInMap: function (projectCode, branch, taskNumber) {
|
||||
var arr = this.projectMap[projectCode][branch];
|
||||
var currentIndex;
|
||||
for (var i = 4; i < arr.length; i++) {
|
||||
if (arr[i] == taskNumber) {
|
||||
currentIndex = i
|
||||
};
|
||||
}
|
||||
|
||||
var nextIndex = currentIndex + 1,
|
||||
previousIndex = currentIndex - 1;
|
||||
var nextTaskNumber = this.projectMap[projectCode][branch][nextIndex],
|
||||
previousTaskNumber = this.projectMap[projectCode][branch][previousIndex];
|
||||
|
||||
var deleteMode;
|
||||
if (currentIndex == (arr.length - 1)) {
|
||||
deleteMode = "last"
|
||||
};
|
||||
if (currentIndex == 4) {
|
||||
deleteMode = "first"
|
||||
};
|
||||
if ((currentIndex > 4) && (currentIndex < (arr.length - 1))) {
|
||||
deleteMode = "normal"
|
||||
};
|
||||
if ((currentIndex == 4) && (currentIndex == (arr.length - 1))) {
|
||||
deleteMode = "nothingToDelete"
|
||||
};
|
||||
|
||||
//Checking for links elsewhere
|
||||
var otherBranches = Object.keys(this.projectMap[projectCode]);
|
||||
//Remove the native branch and mainLine from otherBranches list
|
||||
otherBranches.splice(otherBranches.indexOf(branch), 1);
|
||||
otherBranches.splice(otherBranches.indexOf("mainLine"), 1);
|
||||
|
||||
//Checking the link other branches
|
||||
for (var i = 0; i < otherBranches.length; i++) {
|
||||
|
||||
|
||||
if (this.projectMap[projectCode][otherBranches[i]][2] == taskNumber) {
|
||||
|
||||
|
||||
if (deleteMode == "normal") {
|
||||
this.projectMap[projectCode][otherBranches[i]][2] = previousTaskNumber
|
||||
} else if (deleteMode == "last") {
|
||||
this.projectMap[projectCode][otherBranches[i]][2] = previousTaskNumber
|
||||
} else if (deleteMode == "first") {
|
||||
this.projectMap[projectCode][otherBranches[i]][2] = nextTaskNumber
|
||||
} else if (deleteMode == "undefined") {
|
||||
return " nothing to delete"
|
||||
}
|
||||
}
|
||||
|
||||
if (this.projectMap[projectCode][otherBranches[i]][3] == taskNumber) {
|
||||
|
||||
if (deleteMode == "normal") {
|
||||
this.projectMap[projectCode][otherBranches[i]][3] = nextTaskNumber
|
||||
} else if (deleteMode == "last") {
|
||||
this.projectMap[projectCode][otherBranches[i]][3] = previousTaskNumber
|
||||
} else if (deleteMode == "first") {
|
||||
this.projectMap[projectCode][otherBranches[i]][3] = nextTaskNumber
|
||||
} else if (deleteMode == "undefined") {
|
||||
return " nothing to delete"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
} //end for loop
|
||||
|
||||
//Delete from other databases
|
||||
|
||||
var p = this.projectTaskDetails;
|
||||
|
||||
for (var key in p) {
|
||||
if (p.hasOwnProperty(key)) {
|
||||
if (key == projectCode + "_" + branch + "_" + taskNumber) {
|
||||
delete p[key]
|
||||
}
|
||||
}
|
||||
} // end function
|
||||
|
||||
|
||||
//Now splice the element
|
||||
arr.splice(currentIndex, 1);
|
||||
arr[1] = arr[1] - 1;
|
||||
|
||||
},
|
||||
|
||||
insertTaskInMap: function (projectCode, branchName, insertPoint) {
|
||||
var lastTasks = [];
|
||||
lastTasks = findLastTaskNumber(projectCode);
|
||||
var lastNumber = lastTasks[branchName];
|
||||
var arr = this.projectMap[projectCode][branchName];
|
||||
var addedTaskNumber = lastNumber + 1;
|
||||
var insertIndex = 0;
|
||||
|
||||
//Find insert point index
|
||||
for (var i = 4; i < arr.length; i++) {
|
||||
if (arr[i] >= addedTaskNumber) {
|
||||
addedTaskNumber = arr[i] + 1
|
||||
}
|
||||
if (arr[i] == insertPoint) {
|
||||
insertIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (insertIndex > 3) {
|
||||
arr.splice((insertIndex + 1), 0, addedTaskNumber);
|
||||
arr[1]++;
|
||||
} else {
|
||||
return "Not possible to insert here.Try another position"
|
||||
}
|
||||
|
||||
return addedTaskNumber;
|
||||
},
|
||||
|
||||
|
||||
//The best error management I have done
|
||||
//Project changing is overdoing right now
|
||||
//newStartPoint,newEndPoint is optional
|
||||
changeBranchLine: function (projectCode, branch, newConnection, newStartPoint, newEndPoint) {
|
||||
//find the task number on the original line where it was branched, and then close the line there
|
||||
//Do some basic tests
|
||||
if (branch == "mainLine") {
|
||||
return "You cannot change mainLine";
|
||||
}
|
||||
if (this.projectMap.hasOwnProperty(projectCode) == false) {
|
||||
return "The project does not exist"
|
||||
}
|
||||
if (this.projectMap[projectCode].hasOwnProperty(branch) == false) {
|
||||
return "The branch does not exist"
|
||||
}
|
||||
if (this.projectMap[projectCode].hasOwnProperty(newConnection) == false) {
|
||||
return "The newConnection does not exist"
|
||||
}
|
||||
if (newStartPoint > newEndPoint) {
|
||||
return "Startpoint cannot be later than endpoint"
|
||||
}
|
||||
|
||||
this.projectMap[projectCode][branch][0] = newConnection;
|
||||
if (newStartPoint != "undefined") {
|
||||
this.projectMap[projectCode][branch][2] = newStartPoint;
|
||||
}
|
||||
if (newEndPoint != "undefined") {
|
||||
this.projectMap[projectCode][branch][3] = newEndPoint;
|
||||
}
|
||||
|
||||
return this.projectMap[projectCode][branch];
|
||||
},
|
||||
|
||||
//startOrEndOrNewProject 1=>Start,2=>End .. projectCode and branch will remain same .. mainLines cannot be rerouted
|
||||
//One test is missing .. you cannot connect to a point after end of connected trunk .. do it later .. not critical
|
||||
changeBranchPoint: function (projectCode, branch, newPoint, startOrEnd) {
|
||||
var message;
|
||||
|
||||
if (branch != "mainLine") {
|
||||
|
||||
if (startOrEnd == 1) {
|
||||
if (newPoint <= this.projectMap[projectCode][branch][3]) {
|
||||
this.projectMap[projectCode][branch][2] = newPoint;
|
||||
message = newPoint;
|
||||
} else {
|
||||
message = "Start point cannot be later than end point"
|
||||
}
|
||||
}
|
||||
|
||||
if (startOrEnd == 2) {
|
||||
if (newPoint >= this.projectMap[projectCode][branch][2]) {
|
||||
this.projectMap[projectCode][branch][3] = newPoint;
|
||||
message = newPoint;
|
||||
} else {
|
||||
message = "End point cannot be earlier than start point"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (branch == "mainLine") {
|
||||
message = "mainLine cannot be rerouted"
|
||||
}
|
||||
return message;
|
||||
},
|
||||
|
||||
|
||||
|
||||
addBranch: function (projectCode1, branch, startPoint, mergePoint) {
|
||||
var arr = findAllBranches(projectCode1);
|
||||
var newBranchName;
|
||||
|
||||
if (arr == false) {
|
||||
this.projectMap[projectCode1] = {};
|
||||
this.projectMap[projectCode1]["mainLine"] = ["mainLine", 0, "Start", "Stop"];
|
||||
newBranchName = "mainLine";
|
||||
this.projectBranches[projectCode1] = "mainLine";
|
||||
//projectCode[projectCode.length] = projectCode1;
|
||||
} else {
|
||||
var str = arr[arr.length - 1];
|
||||
|
||||
if (str.includes("branch")) {
|
||||
var res = str.split("branch");
|
||||
var newNumber = parseFloat(res[1]) + 1;
|
||||
newBranchName = "branch" + newNumber;
|
||||
this.projectMap[projectCode1]["branch" + newNumber] = [branch, 0, startPoint, mergePoint];
|
||||
this.projectBranches[projectCode1] = this.projectBranches[projectCode1] + "," + "branch" +
|
||||
newNumber;
|
||||
}
|
||||
|
||||
if (str.includes("mainLine")) {
|
||||
newBranchName = "branch1";
|
||||
this.projectMap[projectCode1]["branch1"] = ["mainLine", 0, startPoint, mergePoint];
|
||||
this.projectBranches[projectCode1] = "mainLine,branch1";
|
||||
}
|
||||
}
|
||||
return newBranchName;
|
||||
},
|
||||
|
||||
|
||||
readTaskDetails: function (projectCode, branch, taskNumber) {
|
||||
return this.projectTaskDetails[projectCode + "_" + branch + "_" + taskNumber];
|
||||
},
|
||||
|
||||
putTaskDetails: function (taskDetails, projectCode, branch, taskNumber) {
|
||||
//add taskDetails
|
||||
this.projectTaskDetails[projectCode + "_" + branch + "_" + taskNumber] = taskDetails;
|
||||
},
|
||||
|
||||
addTaskInMap: function (projectCode, branchName) {
|
||||
var lastTasks = [];
|
||||
lastTasks = findLastTaskNumber(projectCode);
|
||||
var lastNumber = lastTasks[branchName];
|
||||
|
||||
var addedTaskNumber = lastNumber + 1;
|
||||
this.projectMap[projectCode][branchName].push(addedTaskNumber);
|
||||
this.projectMap[projectCode][branchName][1]++;
|
||||
|
||||
return addedTaskNumber
|
||||
},
|
||||
|
||||
findAllBranches: function (projectCode) {
|
||||
if (this.projectBranches.hasOwnProperty(projectCode)) {
|
||||
var branch = this.projectBranches[projectCode].split(",");
|
||||
} else branch = false;
|
||||
|
||||
return branch;
|
||||
},
|
||||
|
||||
|
||||
findLastTaskNumber: function (projectCode) {
|
||||
var returnData = {};
|
||||
//Find all branch lines
|
||||
|
||||
var branch = this.projectBranches[projectCode].split(",");
|
||||
|
||||
|
||||
for (var i = 0; i < branch.length; i++) {
|
||||
returnData[branch[i]] = this.projectMap[projectCode][branch[i]][1];
|
||||
|
||||
//This test seems to have become redundant
|
||||
if (returnData[branch[i]] == "Stop") {
|
||||
returnData[branch[i]] = 0
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user