Skip to content

Commit

Permalink
Merge pull request #75 from TexasDigitalLibrary/4.0.x-settings-refactor
Browse files Browse the repository at this point in the history
4.0.x settings refactor
  • Loading branch information
gadkrumholz committed Feb 19, 2016
2 parents 4a6a275 + 57648bd commit 831f761
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 170 deletions.
19 changes: 12 additions & 7 deletions src/main/java/org/tdl/vireo/controller/SettingsController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.tdl.vireo.controller;

import static edu.tamu.framework.enums.ApiResponseType.SUCCESS;
import static edu.tamu.framework.enums.ApiResponseType.ERROR;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -14,6 +16,7 @@
import org.tdl.vireo.service.DefaultSettingsService;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import edu.tamu.framework.aspect.annotation.ApiMapping;
Expand Down Expand Up @@ -48,16 +51,18 @@ public ApiResponse getSettings() {

@ApiMapping("/update")
public ApiResponse updateSetting(@Data String data) {
Map<String,String> map = new HashMap<String,String>();

JsonNode dataNode;
try {
map = objectMapper.readValue(data, new TypeReference<HashMap<String,String>>(){});
} catch (Exception e) {
e.printStackTrace();
}
configurationRepo.create(map.get("setting"),map.get("value"),map.get("type"));
dataNode = objectMapper.readTree(data);
} catch (IOException e) {
return new ApiResponse(ERROR, "Unable to parse update json ["+e.getMessage()+"]");
}

configurationRepo.create(dataNode.get("setting").asText(),dataNode.get("value").asText(),dataNode.get("type").asText());

Map<String, Map<String,String>> typeToConfigPair = new HashMap<String, Map<String,String>>();
typeToConfigPair.put(map.get("type"),configurationRepo.getAllByType(map.get("type")));
typeToConfigPair.put(dataNode.get("type").asText(),configurationRepo.getAllByType(dataNode.get("type").asText()));
this.simpMessagingTemplate.convertAndSend("/channel/settings", new ApiResponse(SUCCESS, typeToConfigPair));

return new ApiResponse(SUCCESS);
Expand Down
17 changes: 9 additions & 8 deletions src/main/resources/SYSTEM_Defaults.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"application":[
{"submissions_open":true},
{"current_semester":"Spring 2016"},
{"grantor":"Texas A&M University"},
{"email_from":"[email protected]"},
{"email_reply_to":"[email protected]"}
],
{"submissions_open":false},
{"allow_multiple_submissions":false},
{"current_semester":"Spring 2016"},
{"grantor":"Texas A&M University"},
{"email_from":"[email protected]"},
{"email_reply_to":"[email protected]"}
],
"theme":[
{"background_main_color":"#1b333f"},
{"background_highlight_color":"#43606e"},
{"button_main_color_on":"#1b333f"},
{"button_highlight_color_on":"#43606e"},
{"button_main_color_off":"#a6a18c"},
{"button_highlight_color_off":"#c7c2a9"}
],
],
"orcid":[
{"orcid_validation":"true"},
{"orcid_authentication":"false"}
]
]
}
68 changes: 38 additions & 30 deletions src/main/webapp/WEB-INF/app/controllers/settingsController.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
vireo.controller("SettingsController", function ($controller, $scope, $location, $routeParams, User, UserSettings, ApplicationSettings, SidebarService) {
vireo.controller("SettingsController", function ($controller, $scope, $q, $location, $routeParams, User, UserSettings, ConfigurableSettings, SidebarService) {
angular.extend(this, $controller("AbstractController", {$scope: $scope}));

$scope.clicked=false;
$scope.user = User.get();

$scope.getTest = function() {
console.log("foo");
};

$scope.settings = {};
$scope.settings.application = ApplicationSettings.get();
$scope.settings.user = UserSettings.get();

$scope.ready = UserSettings.ready;

UserSettings.ready().then(function() {
$scope.ready = $q.all([UserSettings.ready(), ConfigurableSettings.ready()]);

$scope.settings.user = UserSettings.get();
$scope.settings.configurable = ConfigurableSettings.get();

$scope.ready.then(function() {

$scope.updateUserSetting = function(setting, timer) {
if(Object.keys($scope.userSettingsForm.$error).length) return;

Expand All @@ -25,45 +21,57 @@ vireo.controller("SettingsController", function ($controller, $scope, $location,
$scope.typingTimer = setTimeout(function() {
UserSettings.update(setting, $scope.settings.user[setting]);
}, timer);

};
// $scope.updateApplicationSettings = function(type, setting) {

// ApplicationSettings.update(type, $scope.settings.application[type][setting]);
// }
});
$scope.updateConfigurableSettings = function(type,setting) {
ConfigurableSettings.update(type,setting,$scope.settings.configurable[type][setting]);
};

$scope.resetConfigurableSettings = function(type,setting) {
ConfigurableSettings.reset(type,setting);
};

$scope.toggle = function(clicked) {
$scope.clicked=!clicked;
};
});

$scope.editMode = function(prop) {
$scope["edit"+prop] = true;
};

$scope.viewMode = function(prop) {

$scope["edit"+prop] = false;
}

$scope.confirmEdit = function($event, prop) {
if($event.keyCode == 13) $scope["edit"+prop] = false;
if($event.which == 13) {

if(prop) $scope["edit"+prop] = false;

$event.target.blur();

}
}

$scope.hasError = function(field) {

if(!field) field = {};

return Object.keys(field).length > 0;
}

$scope.updateApplicationSettings = function(type,setting,value) {
ApplicationSettings.update(type,setting,$scope.settings.application[type][setting]);
};

$scope.resetApplicationSettings = function(type,setting) {
ApplicationSettings.reset(type,setting);
};
/**
* Toggle options
*
* {evaluation: gloss}
*
*/

//Submission Availability pane
$scope.submissionsOpenOptions = [
{"true": "Open"},
{"false": "Closed"}
];

$scope.allowMultipleSubmissionsOptions = [
{"true": "Yes"},
{"false": "No"}
];

});
49 changes: 21 additions & 28 deletions src/main/webapp/WEB-INF/app/directives/togglebuttonDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,32 @@ vireo.directive("togglebutton", function() {
return {
templateUrl: 'views/directives/toggleButton.html',
restrict: 'E',
replace: false,
transclude: true,
scope: {},
scope: {
"label": "@",
"scopeValue": "=",
"toggleOptions": "@"
},
controller: function($scope) {

this.setActive = function(option) {
$scope.activeButton = option;
}
$scope.setActive = function(scopeValue) {
$scope.scopeValue = scopeValue;
}

this.optionActive = function(option) {
return $scope.activeButton == option;
}
},
link: function ($scope, element, attr) {
$scope.label = attr.label;
}
};
});

vireo.directive("toggleoption", function() {
return {
template: '<button class="btn btn-sm btn-default" ng-click="setActive(option)" ng-class="{\'active\': optionActive(option)}" ng-transclude></button>',
restrict: 'E',
replace: true,
require: '^togglebutton',
transclude: true,
scope: true,
link: function ($scope, element, attr, parent) {
$scope.option = element.children('span').html();
angular.extend($scope, parent);
angular.extend($scope, attr);
link: function($scope, element, attr) {

var optionsObj = angular.fromJson($scope.toggleOptions)

$scope.options = {};

for(var index in optionsObj) {
var option = optionsObj[index];
$scope.options["option"+ index] = {
gloss: option[Object.keys(option)[0]],
evaluation: Object.keys(option)[0]
}
}
}
}
};
});

2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/app/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
<!-- Factories -->

<!-- Models -->
<script src="model/applicationSettingsModel.js"></script>
<script src="model/configurableSettingsModel.js"></script>
<script src="model/organizationRepoModel.js"></script>
<script src="model/userSettingsModel.js"></script>
<script src="model/userRepoModel.js"></script>
Expand Down
71 changes: 0 additions & 71 deletions src/main/webapp/WEB-INF/app/model/applicationSettingsModel.js

This file was deleted.

Loading

0 comments on commit 831f761

Please sign in to comment.