Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6 missions per row, multi user support, changed menu link texts #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions IMATTC.user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ==UserScript==
// @name IMATTC
// @version 1.8.0
// @version 1.8.1
// @description A usability overhaul for the Ingress Mission Authoring Tool
// @author @Chyld314
// @author @Chyld314 @DanielOndiordna
// @match https://mission-author-dot-betaspike.appspot.com/
// @match https://mission-author-dot-betaspike.appspot.com/edit*
// @match http://missions.ingress.com/
Expand Down Expand Up @@ -105,6 +105,9 @@ $(function() {
+ ".mission-list-item-submitted_and_published .button:hover {background-color: #4d6619;}"
+ ".mission-list-item-submitted_and_published .button .caret {border-bottom-color: springgreen;}";

newCssRules += ".col-md-3 { width: 16.6%; }"
+ ".container { width: 100%; }";

newCssRules += ".dropup {position: relative;}"
+ ".dropup .dropdown-menu {top: initial; bottom: 30px; left: 0; right: 0; text-align: center;}"
+ ".dropdown-menu > li > a {cursor: pointer;}"
Expand Down Expand Up @@ -224,6 +227,25 @@ function init() {
//$('body').css('margin-top','0');
};

function storeCategoryContent(categoryContent) {
let activeuser = $('.navbar-login a').first().text().trim(); // expect username here
w.localStorage.setItem('allCategories_' + activeuser, JSON.stringify(categoryContent));
}
function restoreCategoryContent() {
if (w.localStorage.getItem('allCategories')) { // convert old storage to new storage per user
let categoryContentJSON = JSON.parse(w.localStorage.getItem('allCategories')) || [];
storeCategoryContent(categoryContentJSON);
w.localStorage.removeItem('allCategories');
return categoryContentJSON;
}
let activeuser = $('.navbar-login a').first().text().trim(); // expect username here
return JSON.parse(w.localStorage.getItem('allCategories_' + activeuser)) || [];
}
function removeCategoryContent() {
let activeuser = $('.navbar-login a').first().text().trim(); // expect username here
w.localStorage.removeItem('allCategories_' + activeuser);
}

function missionEditSetup(editScope) {
var editStep = editScope.mission.ui.view;

Expand All @@ -244,7 +266,7 @@ function init() {
editScope.categoryContent[editScope.selectedCategoryID].missions.push(editScope.savedWireMission.mission_guid);
editScope.categoryContent[editScope.selectedCategoryID].collapse = false;
editScope.selectedCategoryID = null;
w.localStorage.setItem('allCategories', JSON.stringify(editScope.categoryContent));
storeCategoryContent(editScope.categoryContent);
}
w.$location.url("/")
}).error(function(b) {
Expand Down Expand Up @@ -347,7 +369,7 @@ function init() {
break;
case editScope.EditorScreenViews.PREVIEW:
//If there are user generated categories, add a dropdown to add the new mission to one
editScope.categoryContent = JSON.parse(w.localStorage.getItem('allCategories')) || [];
editScope.categoryContent = restoreCategoryContent();
if (editScope.categoryContent.length > 0 && editScope.mission.mission_guid){
var showCategory = true;
editScope.categoryContent.forEach(function(category){
Expand Down Expand Up @@ -426,7 +448,7 @@ function init() {
missionScope.uncategorisedSort = 'initial';
missionScope.missions = w.$filter("orderBy")(missionScope.missions, 'definition.name');
missionScope.loadingPreview = false;
missionScope.unsortedCollapse = {collapse: w.localStorage.getItem('unsortedCollapse') || true};
missionScope.unsortedCollapse = {collapse: JSON.parse(w.localStorage.getItem('unsortedCollapse') || true)};

//handling for legacy data format
if (!!w.localStorage.getItem('categoryNames')){
Expand All @@ -445,15 +467,15 @@ function init() {
missionScope.categoryContent.push(thisCategory);
w.localStorage.removeItem('categoryContent' + i);
}
w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent));
storeCategoryContent(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.categoryContent = restoreCategoryContent();
missionScope.selectedCategoryMissionId = null;

//Add position in initial array
Expand Down Expand Up @@ -586,7 +608,7 @@ function init() {
missionScope.categoryContent[categoryID].collapse = false;
missionScope.selectedCategoryMissionId = null;
missionScope.selectedCategoryID = null;
w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent));
storeCategoryContent(missionScope.categoryContent);
generateAllMissions();
}

Expand All @@ -596,7 +618,7 @@ function init() {
missionScope.categoryContent[category].missions.splice(i, 1);
}
}
w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent));
storeCategoryContent(missionScope.categoryContent);
generateAllMissions();
}

Expand All @@ -614,22 +636,22 @@ function init() {
sortCriteria: 'initial'
};
missionScope.categoryContent.push(newCategory);
w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent));
storeCategoryContent(missionScope.categoryContent);
generateAllMissions();
}
}

missionScope.nukeCategories = function() {
missionScope.categoryContent = [];
w.localStorage.setItem('allCategories', null);
removeCategoryContent();
generateAllMissions();
}

missionScope.deleteCategory = function(category) {
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.")) {
//nuke localStorage category
missionScope.categoryContent.splice(category, 1);
w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent));
storeCategoryContent(missionScope.categoryContent);
generateAllMissions();
}
}
Expand All @@ -648,7 +670,7 @@ function init() {
missionScope.toggleCollapse = function(collapse, unsorted){
collapse.collapse = !collapse.collapse;
unsorted ? w.localStorage.setItem('unsortedCollapse', collapse.collapse)
: w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent));
: storeCategoryContent(missionScope.categoryContent);
}

missionScope.dragMissions = function(start_pos, start_cat, end_pos, end_cat) {
Expand Down Expand Up @@ -686,7 +708,7 @@ function init() {
}

//then regenerate everything
w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent));
storeCategoryContent(missionScope.categoryContent);
generateAllMissions();
}

Expand Down Expand Up @@ -771,10 +793,10 @@ function init() {
}
if (selectedCategory === false) {
//adding unsorted mission to category
newMissionCode += "<li><a role='button' ng-click='selectACategory(missions[" + id + "])' data-toggle='modal' data-target='#addCateModel'>Add To Category...</a></li>";
newMissionCode += "<li><a role='button' ng-click='selectACategory(missions[" + id + "])' data-toggle='modal' data-target='#addCateModel'>Move To Category...</a></li>";
} else {
//removing a mission from a category
newMissionCode += "<li><a role='button' ng-click='removeFromCategory(" + selectedCategory + ", missions[" + id + "])'>Remove From Category</a></li>";
newMissionCode += "<li><a role='button' ng-click='removeFromCategory(" + selectedCategory + ", missions[" + id + "])'>Move to Unsorted Missions</a></li>";
}
newMissionCode += "</ul></div>"
newMissionCode += "</div></div>";
Expand Down Expand Up @@ -838,7 +860,7 @@ function init() {
if (mission == undefined){
missionScope.categoryContent[i].missions.splice(j,1);
j--;
w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent));
storeCategoryContent(missionScope.categoryContent);
} else {
missionContent += generateMission(mission, mission.position, i);
bannerModal += "<div class='col-xs-2'><img class='img-responsive' src='" + (mission.definition.logo_url ? mission.definition.logo_url : "/images/button_logo.png") + "' /></div>";
Expand Down Expand Up @@ -930,7 +952,7 @@ function init() {
//try to parse data, then turn it into object
try {
missionScope.categoryContent = JSON.parse(dataInput);
w.localStorage.setItem('allCategories', JSON.stringify(missionScope.categoryContent));
storeCategoryContent(missionScope.categoryContent);
generateAllMissions();
} catch (e){
alert('Something went wrong!!');
Expand Down