Skip to content

Commit

Permalink
Restrict editor programs for mapping and validation stages
Browse files Browse the repository at this point in the history
**This PR includes a db migration**
Related Issue: #893

* Added list of editors in the `Settings` menu of a project-edit page where a project manager can select permitted editors for each editing stage
* Updated the editor dropdown for to populate only with the permitted editors
* requirements for at least one editor to be selected
* relocate warnings to the appropriate field
* added exclamation points for tabs causing errors
  • Loading branch information
Zack LaVergne authored and arunasank committed May 17, 2019
1 parent 05755c2 commit 4a5b239
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 56 deletions.
91 changes: 91 additions & 0 deletions client/app/admin/edit-project/edit-project.controller.js
Expand Up @@ -40,6 +40,22 @@
other: false
};

// Editors for mapping
vm.mappingEditors = {
id: false,
josm: false,
potlatch2: false,
fieldpapers: false
};

// Editors for validation
vm.validationEditors = {
id: false,
josm: false,
potlatch2: false,
fieldpapers: false
};

// Tags
vm.organisationTags = [];
vm.campaignsTags = [];
Expand Down Expand Up @@ -82,6 +98,9 @@
// Form
vm.form = {};

// User role
vm.userRole = '';

activate();

function activate() {
Expand All @@ -99,6 +118,7 @@
if (session){
var resultsPromise = accountService.getUser(session.username);
resultsPromise.then(function (user) {
vm.userRole = user.role;
// Returned the user successfully. Check the user's role
if (user.role !== 'PROJECT_MANAGER' && user.role !== 'ADMIN'){
$location.path('/');
Expand Down Expand Up @@ -167,6 +187,8 @@
// Prepare the data for sending to API by removing any locales with no fields
if (!requiredFieldsMissing && vm.editForm.$valid){
vm.project.mappingTypes = getMappingTypesArray();
vm.project.mappingEditors = getMappingEditorsArray();
vm.project.validationEditors = getValidationEditorsArray();
vm.project.josmPreset = vm.josmPreset;
for (var i = 0; i < vm.project.projectInfoLocales.length; i++){
var info = vm.project.projectInfoLocales[i];
Expand Down Expand Up @@ -790,6 +812,8 @@
vm.project.dueDate = new Date(vm.project.dueDate);
}
populateTypesOfMapping();
populateEditorsForMapping();
populateEditorsForValidation();
addAOIToMap();
addPriorityAreasToMap();
if (vm.project.organisationTag) {
Expand Down Expand Up @@ -928,6 +952,73 @@
return mappingTypesArray;
}

/**
* Populate the mapping editor fields by checking which tags exist
* in the mappingEditors array on the project
*/
function populateEditorsForMapping(){
if (vm.project.mappingEditors) {
vm.mappingEditors.id = vm.project.mappingEditors.indexOf("ID") != -1;
vm.mappingEditors.josm = vm.project.mappingEditors.indexOf("JOSM") != -1;
vm.mappingEditors.potlatch2 = vm.project.mappingEditors.indexOf("POTLATCH_2") != -1;
vm.mappingEditors.fieldpapers = vm.project.mappingEditors.indexOf("FIELD_PAPERS") != -1;
}
}

/**
* Get map editors in array
*/
function getMappingEditorsArray(){
var mappingEditorsArray = [];
if (vm.mappingEditors.id){
mappingEditorsArray.push("ID");
}
if (vm.mappingEditors.josm){
mappingEditorsArray.push("JOSM");
}
if (vm.mappingEditors.potlatch2) {
mappingEditorsArray.push("POTLATCH_2");
}
if (vm.mappingEditors.fieldpapers){
mappingEditorsArray.push("FIELD_PAPERS");
}
return mappingEditorsArray;
}


/**
* Populate the validation editor fields by checking which tags exist
* in the validationEditors array on the project
*/
function populateEditorsForValidation(){
if (vm.project.validationEditors) {
vm.validationEditors.id = vm.project.validationEditors.indexOf("ID") != -1;
vm.validationEditors.josm = vm.project.validationEditors.indexOf("JOSM") != -1;
vm.validationEditors.potlatch2 = vm.project.validationEditors.indexOf("POTLATCH_2") != -1;
vm.validationEditors.fieldpapers = vm.project.validationEditors.indexOf("FIELD_PAPERS") != -1;
}
}

/**
* Get validate editors in array
*/
function getValidationEditorsArray(){
var validationEditorsArray = [];
if (vm.validationEditors.id){
validationEditorsArray.push("ID");
}
if (vm.validationEditors.josm){
validationEditorsArray.push("JOSM");
}
if (vm.validationEditors.potlatch2) {
validationEditorsArray.push("POTLATCH_2");
}
if (vm.validationEditors.fieldpapers){
validationEditorsArray.push("FIELD_PAPERS");
}
return validationEditorsArray;
}

/**
* Set organisation tags
*/
Expand Down

0 comments on commit 4a5b239

Please sign in to comment.