From 8ad1ef49b76eb6fb307e80ec7e06f857c868adb6 Mon Sep 17 00:00:00 2001 From: andyjennings314 Date: Fri, 12 Jul 2019 20:46:09 +0100 Subject: [PATCH 1/5] Reconfigured data storage, introduced data export --- IMATTC.user.js | 246 +++++++++++++++++++++++++++---------------------- 1 file changed, 134 insertions(+), 112 deletions(-) diff --git a/IMATTC.user.js b/IMATTC.user.js index 16f6705..72304d6 100644 --- a/IMATTC.user.js +++ b/IMATTC.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name IMATTC -// @version 1.4.2 +// @version 1.5.0 // @description A usability overhaul for the Ingress Mission Authoring Tool // @author @Chyld314 // @match https://mission-author-dot-betaspike.appspot.com/ @@ -302,52 +302,63 @@ function init() { return dfd.promise; } + missionScope.categoryContent = []; missionScope.missions = w.$filter("orderBy")(missionScope.missions, 'definition.name'); missionScope.loadingPreview = false; - //missionScope.getFullMissionData(missionScope.missions).then(function(data){ - //for (var i=0;i 0) { - missionScope.categoryContent = []; - //create uncategorised mission bucket, that categories will take missions from. Add position in initial array - for (var i = 0; i < missionScope.missions.length; i++) { - missionScope.missions[i].position = i; - } - missionScope.uncategorisedMissions = angular.copy(missionScope.missions); - - //loop through each category of GUIDs, and add actual missions to scope - categoryGUIDs.forEach(function(category) { - var catobj = []; - category.forEach(function(guid) { - for (var i = 0; i < missionScope.uncategorisedMissions.length ; i++) { - //once the right mission is found, add position, push it to the holding array and remove from uncategorised - if (missionScope.uncategorisedMissions[i].mission_guid == guid) { - catobj.push(missionScope.uncategorisedMissions[i]); - missionScope.uncategorisedMissions.splice(i, 1); - break; - } - } - }) - missionScope.categoryContent.push(catobj) - }) + missionScope.unsortedCollapse = w.localStorage.getItem('unsortedCollapse') || true; + + //handling for legacy data format + if (!!w.localStorage.getItem('categoryNames')){ + let oldegoriesLength = parseInt(w.localStorage.getItem('categoriesLength')) || 0, + categoryNames = w.localStorage.getItem('categoryNames') ? w.localStorage.getItem('categoryNames').split(',') : [], + thisCategory; + //create categories in new format + for (var i= 0; i < oldegoriesLength; i++){ + thisCategory = { + id: i, + name: categoryNames[i], + missions: w.localStorage.getItem('categoryContent' + i) ? w.localStorage.getItem('categoryContent' + i).split(',') : [], + collapse: true + }; + missionScope.categoryContent.push(thisCategory); + w.localStorage.removeItem('categoryContent' + i); } + w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent)); - //}) + //now tidy up the legacy data + w.localStorage.removeItem('categoryNames'); + w.localStorage.removeItem('categoriesLength'); + } + + //get data for all categories + missionScope.categoryContent = JSON.parse(w.localStorage.getItem('allCategories')) || []; + missionScope.selectedCategoryMissionId = null; + + //now create the categorised/uncategorised missions + if (missionScope.categoryContent.length > 0) { + missionScope.categoryContent = []; + //create uncategorised mission bucket, that categories will take missions from. Add position in initial array + for (var i = 0; i < missionScope.missions.length; i++) { + missionScope.missions[i].position = i; + } + missionScope.uncategorisedMissions = angular.copy(missionScope.missions); + + //loop through each category of GUIDs, and add actual missions to scope + missionScope.categoryContent.forEach(function(category) { + var catobj = []; + category.forEach(function(guid) { + for (var i = 0; i < missionScope.uncategorisedMissions.length ; i++) { + //once the right mission is found, add position, push it to the holding array and remove from uncategorised + if (missionScope.uncategorisedMissions[i].mission_guid == guid) { + catobj.push(missionScope.uncategorisedMissions[i]); + missionScope.uncategorisedMissions.splice(i, 1); + break; + } + } + }) + missionScope.categoryContent.push(catobj) + }) + } //function to calculate distances between two sets of coordinates taken from geodatasource.com missionScope.distance = function(lat1, lon1, lat2, lon2, unit) { @@ -470,7 +481,8 @@ function init() { $(".modal-backdrop.fade").remove(); $("body").removeClass("modal-open"); var categoryID = missionScope.selectedCategoryID; - categoryGUIDs[categoryID].push(missionScope.selectedCategoryMissionId); + missionScope.categoryContent[categoryID].missions.push(missionScope.selectedCategoryMissionId); + missionScope.categoryContent[categoryID].collapse = false; //find mission in uncategorised missions for (var i = 0; i < missionScope.uncategorisedMissions.length; i++) { if (missionScope.uncategorisedMissions[i].mission_guid == missionScope.selectedCategoryMissionId) { @@ -480,22 +492,21 @@ function init() { } } missionScope.selectedCategoryMissionId = null; - w.localStorage.setItem('categoryContent' + categoryID, categoryGUIDs[categoryID]); - missionScope.categoryCollapse[categoryID] = true; missionScope.selectedCategoryID = null; + w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent)); generateAllMissions(); } missionScope.removeFromCategory = function(category, mission) { - for (var i = 0; i < categoryGUIDs[category].length; i++) { - if (categoryGUIDs[category][i] == mission.mission_guid) { + for (var i = 0; i < missionScope.categoryContent[category].missions.length; i++) { + if (missionScope.categoryContent[category].missions[i] == mission.mission_guid) { missionScope.uncategorisedMissions.push(mission); missionScope.categoryContent[category].splice(i, 1); categoryGUIDs[category].splice(i, 1); } } - w.localStorage.setItem('categoryContent' + category, categoryGUIDs[category]); - missionScope.categoryCollapse[category] = true; + missionScope.categoryContent[category].collapse = false; + w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent)); generateAllMissions(); } @@ -504,44 +515,32 @@ function init() { if (categoryName == null || categoryName == "") { //no result } else { - //create category elements in various places - categoriesLength++; - w.localStorage.setItem('categoriesLength', categoriesLength); - categoryNames.push(categoryName); - w.localStorage.setItem('categoryNames', categoryNames); - missionScope.categoryContent = missionScope.categoryContent || []; - categoryGUIDs.push([]); - missionScope.categoryContent.push([]); - w.localStorage.setItem('categoryContent' + (categoriesLength - 1), []); + //create category elements + var newCategory = { + id: missionScope.categoryContent.length, + name: categoryName, + missions: [], + collapse: false + }; + missionScope.categoryContent.push(newCategory); + w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent)); generateAllMissions(); } } missionScope.nukeCategories = function() { - w.localStorage.clear(); + missionScope.categoryContent = []; + w.localStorage.setItem('allCategories', []); generateAllMissions(); } missionScope.deleteCategory = function(category) { - if (confirm("Are you sure you want to delete the " + categoryNames[category] + " category? Any missions you've placed in this category will be retured to Unsorted missions.")) { - //remove cateory from GUID list, move scope missions out, nuke localStorage categories - categoryGUIDs.splice(category, 1); + if (confirm("Are you sure you want to delete the " + missionScope.categoryContent[category].name + " category? Any missions you've placed in this category will be retured to Unsorted missions.")) { + //move scope missions out, nuke localStorage categories missionScope.categoryContent[category].forEach(function(mission) { missionScope.uncategorisedMissions.push(mission); }) missionScope.categoryContent.splice(category, 1); - for (var i = 0; i < categoriesLength; i++) { - w.localStorage.removeItem('categoryContent' + i); - } - //remove other mission data - categoriesLength--; - w.localStorage.setItem('categoriesLength', categoriesLength); - categoryNames.splice(category, 1); - w.localStorage.setItem('categoryNames', categoryNames); - missionScope.categoryCollapse.splice(category, 1); - //then rebuild localStorage - for (var i = 0; i < categoriesLength; i++) { - w.localStorage.setItem('categoryContent' + i, categoryGUIDs[i]); - } + w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent)); generateAllMissions(); } } @@ -550,9 +549,9 @@ function init() { if (category == 'all'){ missionScope.missions = w.$filter("orderBy")(missionScope.missions, missionScope.sortCriteria[0]); } else if (category == 'unsorted'){ - missionScope.uncategorisedMissions = w.$filter("orderBy")(missionScope.uncategorisedMissions, missionScope.sortCriteria[categoriesLength]); + missionScope.uncategorisedMissions = w.$filter("orderBy")(missionScope.uncategorisedMissions, missionScope.sortCriteria[missionScope.categoryContent.length]); } else { - missionScope.categoryContent[category] = w.$filter("orderBy")(missionScope.categoryContent[category], missionScope.sortCriteria[category]); + missionScope.categoryContent[category].missions = w.$filter("orderBy")(missionScope.categoryContent[category].missions, missionScope.sortCriteria[category]); } generateAllMissions(); } @@ -571,7 +570,7 @@ function init() { sortContent += "0"; break; case "unsorted": - sortContent += categoriesLength; + sortContent += missionScope.categoryContent.length; break; default: sortContent += category; @@ -588,13 +587,13 @@ function init() { var generateMission = function(mission, id, selectedCategory) { var missionState = mission.missionListState.toLowerCase(); - var newMissionCode = "
"; - newMissionCode += "
"; - newMissionCode += ""; - newMissionCode += "
"; - newMissionCode += "" + mission.definition.name + ""; - newMissionCode += "
"; - newMissionCode += "
" + + "
" + + "" + + "
" + + "" + mission.definition.name + "" + + "
" + + "" + missionScope.getInfoTime(mission) + ""; - newMissionCode += "" + + "" + missionScope.getInfoTime(mission) + "" + + "
"; - newMissionCode += ""; - newMissionCode += ""; + newMissionCode += "" + + "" + + ""; } - newMissionCode += "
" + missionScope.getMissionRatingString(mission) + " " + mission.stats.num_completed + " " + missionScope.getMissionTimeString(mission) + " " + missionScope.getMissionRatingString(mission) + " " + mission.stats.num_completed + "
"; - newMissionCode += "
"; - newMissionCode += "
"; var compiledContent = $compile(editCode)(editScope); $(".name-view .bordered-panel").append(compiledContent); } @@ -379,8 +374,8 @@ function init() { distance += missionScope.distance( mission.definition.waypoints[i-1]._poi.location.latitude, mission.definition.waypoints[i-1]._poi.location.longitude, - mission.definition.waypoints[i]._poi.location.latitude, - mission.definition.waypoints[i]._poi.location.longitude, + mission.definition.waypoints[i]._poi.location.latitude, + mission.definition.waypoints[i]._poi.location.longitude, "K") } @@ -674,19 +669,19 @@ function init() { //once all the categorisation is done, create the HTML for the categories! missionContent += "
"; for (var i = 0; i < missionScope.categoryContent.length; i++) { - missionContent += "
"; - missionContent += "
"; - missionContent += generateSort(i); - missionContent += ""; + missionContent += "
" + + "
" + + generateSort(i) + + ""; if (!missionScope.categoryContent[i].missions || missionScope.categoryContent[i].missions.length == 0) { //no missions so far! missionContent += "
No missions added to the category yet
"; } else { - missionContent += ""; - missionContent += "
"; + missionContent += "" + + "
"; var bannerModal = ""; //modal for previewing missions - missionContent += ""; + missionContent += ""; // Pass our fragment content to $compile, and call the function that $compile returns with the scope. var compiledContent = $compile(missionContent)(missionScope); @@ -764,9 +758,9 @@ function init() { var buttonContent = "
"; //button for adding categories - buttonContent += ""; - buttonContent += ""; - buttonContent += ""; + buttonContent += "" + + "" + + ""; //buttonContent += ""; //tally up available missions, and missions in draft states From 0c0ded669a950c04e0a1828774824bcf9fb30666 Mon Sep 17 00:00:00 2001 From: andyjennings314 Date: Mon, 15 Jul 2019 21:12:13 +0100 Subject: [PATCH 4/5] Updated branch number --- IMATTC.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IMATTC.user.js b/IMATTC.user.js index 7ff37f5..4739a50 100644 --- a/IMATTC.user.js +++ b/IMATTC.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name IMATTC -// @version 1.5.0 +// @version 1.5.1 // @description A usability overhaul for the Ingress Mission Authoring Tool // @author @Chyld314 // @match https://mission-author-dot-betaspike.appspot.com/ From 16408a8088395a4c31be7aaa2d43fb0697677294 Mon Sep 17 00:00:00 2001 From: andyjennings314 Date: Mon, 15 Jul 2019 22:16:57 +0100 Subject: [PATCH 5/5] Proper tracking of collapse toggle --- IMATTC.user.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/IMATTC.user.js b/IMATTC.user.js index 7ff37f5..b1c51f2 100644 --- a/IMATTC.user.js +++ b/IMATTC.user.js @@ -303,7 +303,7 @@ function init() { missionScope.uncategorisedSort = 'initial'; missionScope.missions = w.$filter("orderBy")(missionScope.missions, 'definition.name'); missionScope.loadingPreview = false; - missionScope.unsortedCollapse = w.localStorage.getItem('unsortedCollapse') || true; + missionScope.unsortedCollapse = {collapse: w.localStorage.getItem('unsortedCollapse') || true}; //handling for legacy data format if (!!w.localStorage.getItem('categoryNames')){ @@ -495,6 +495,7 @@ function init() { generateAllMissions(); } } + missionScope.nukeCategories = function() { missionScope.categoryContent = []; w.localStorage.setItem('allCategories', []); @@ -524,6 +525,12 @@ function init() { generateAllMissions(); } + missionScope.toggleCollapse = function(collapse, unsorted){ + collapse.collapse = !collapse.collapse; + unsorted ? w.localStorage.setItem('unsortedCollapse', collapse.collapse) + : w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent)); + } + var generateSort = function (category){ var criteria = [ {name: "Initial", value: "initial"}, @@ -670,7 +677,7 @@ function init() { missionContent += "
"; for (var i = 0; i < missionScope.categoryContent.length; i++) { missionContent += "
" + "
" @@ -695,7 +702,7 @@ function init() { } //add unsorted missions if there are any missionContent += "
" + "
" + generateSort('unsorted') + "
";