Skip to content

Commit

Permalink
Merge pull request #133 from diggyk/edit-quest
Browse files Browse the repository at this point in the history
Added edit quest page
  • Loading branch information
mcot2 committed Feb 10, 2016
2 parents 44f8926 + 0817598 commit 33a0a5e
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 4 deletions.
1 change: 1 addition & 0 deletions hermes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,7 @@ def to_dict(self, base_uri=None, expand=None, only_open_labors=False):
if "quests" in expand:
expand.remove("quests")

# FIXME: this should be an ISO time but will require fixing client and web UI as well
out = {
"id": self.id,
"embarkTime": str(self.embark_time),
Expand Down
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.12"
__version__ = "0.7.13"
92 changes: 90 additions & 2 deletions hermes/webapp/src/css/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,14 @@ a {
.quest-number {
padding: 5px;
width: 20%;
font-size: 1.75em;
font-weight: bold;
border-bottom: 2px solid @blue;
span {
font-size: 1.75em;
font-weight: bold;
}
a {
font-size: 0.65em;
}
}
.sub-info {
font-size: 1em;
Expand Down Expand Up @@ -569,6 +574,85 @@ a {
}
}

.quest-editing {
overflow: hidden;
.panel-row {
overflow: hidden;
&.top-row {
.helper-panel {
-webkit-border-radius: 5px 5px 0px 0px;
-moz-border-radius: 5px 5px 0px 0px;
border-radius: 5px 5px 0px 0px;
}
}
&:not(.top-row) {
.helper-panel, .edit-panel {
padding-top: 20px;
}
}
&.bottom-row {
.helper-panel {
-webkit-border-radius: 0px 0px 5px 5px;
-moz-border-radius: 0px 0px 5px 5px;
border-radius: 0px 0px 5px 5px;
padding-bottom: 0;
margin-bottom: 0;
max-height: 8px;
}
.edit-panel {
padding-bottom: 0;
margin-bottom: 0;
max-height: 8px;
}
}
}
.helper-panel {
height: 100%;
background: @unselected-color;
padding: 10px;
padding-bottom: 20010px;
margin-bottom: -20000px;
&:last-of-type {
-webkit-border-radius: 0px 0px 5px 5px;
-moz-border-radius: 0px 0px 5px 5px;
border-radius: 0px 0px 5px 5px;
}
}
.edit-panel {
padding: 10px;
padding-bottom: 20010px;
margin-bottom: -20000px;
&:not(:first-child) {
padding-top: 50px;
}
.edit-block {
-moz-transition: 0.5s ease-out all;
-ms-transition: 0.5s ease-out all;
-o-transition: 0.5s ease-out all;
transition: 0.5s ease-out all;
height: auto;
max-height: 500px;
}
.edit-block.ng-enter {
max-height: 0;
transition: 0.25s ease-out all;
}

.edit-block.ng-enter-active {
max-height: 500px;
}

.edit-block.ng-leave {
max-height: 500px;
transition: 0.25s ease-out all;
}

.edit-block.ng-leave-active {
max-height: 0;
}
}
}

.quest-creation {
overflow: hidden;
.panel-row {
Expand Down Expand Up @@ -792,6 +876,10 @@ a {
padding: 20px;
color: @btn-text-color;
background: @success-color;
button {
border: 1px solid @xlight-blue;
margin-top: 10px;
}
}

#confirmModal {
Expand Down
123 changes: 123 additions & 0 deletions hermes/webapp/src/js/controllers/questEditCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
(function() {
'use strict';

function QuestEditCtrl(hermesService, $q, $routeParams, $location) {
var vm = this;

vm.user = null; // holds the current user; we should only let current owners update quests
vm.today = new Date(); // used to restrict how far back the due date can be set
vm.quest = null; // holds the retrieve quest details

// new values that the user can edit
vm.newCreator = null;
vm.description = null;
vm.targetDate = null;

vm.editingCreator = false; // controls if we show the creator editing field
vm.editingDate = false; // controls if we show the date picker
vm.editingDesc = false; // controls if we show the desc edit field

// various messaging fields
vm.successMessage = null;
vm.errorMessage = null;

hermesService.getCurrentUser().then(function(user){
if (user) {
vm.user = user;
} else {
vm.errorMessages.push("Cannot create a new quest if not authenticated.");
}
});

refreshQuestInfo();

vm.calDateClasser = calDateClasser;
vm.focus = focus;
vm.saveCreator = saveCreator;
vm.saveTargetTime = saveTargetTime;
vm.saveDescription = saveDescription;
vm.refreshQuestInfo = refreshQuestInfo;

////////////////////////////////

function refreshQuestInfo() {
hermesService.getQuestDetails($routeParams.questId).then(function(quest) {
vm.quest = quest;
vm.description = quest.description;
vm.targetDate = new Date();
//vm.targetDate.setDate(new Date(targetDate).getDate());
vm.targetDate.setTime(Math.round(vm.targetDate.getTime() / 900000) * 900000);
});
}

/**
* Adds our classes to the date picker
* @param date the date in question
* @param mode the mode
*/
function calDateClasser(date, mode) {
return "date-picker";
}

/**
* Helper to set focus and select the text
* @param id the item that gets focus
*/
function focus(id) {
setTimeout(function() {
document.getElementById(id).focus();
document.getElementById(id).select();
}, 10);
}

/**
* Change the creator for a quest
*/
function saveCreator() {
hermesService.updateQuest(vm.quest.id, {"creator": vm.newCreator})
.then(function(response) {
vm.successMessage = "Updated creator to " + vm.newCreator;
vm.newCreator = null;
vm.editingCreator = false;
vm.refreshQuestInfo();
})
.catch(function(error) {
vm.errorMessage = "Error updating creator: " + error.statusText;
})
}

/**
* Change the target time for a quest
*/
function saveTargetTime() {
hermesService.updateQuest(vm.quest.id, {"targetTime": vm.targetDate})
.then(function(response) {
vm.successMessage = "Updated target time to " + vm.targetDate;
vm.editingDate = false;
vm.refreshQuestInfo();
})
.catch(function(error) {
vm.errorMessage = "Error updating target time: " + error.statusText;
})
}

/**
* Change the description for a quest
*/
function saveDescription() {
hermesService.updateQuest(vm.quest.id, {"description": vm.description})
.then(function(response) {
vm.successMessage = "Updated description!";
vm.editingDesc = false;
vm.refreshQuestInfo();
})
.catch(function(error) {
vm.errorMessage = "Error updating description: " + error.statusText;
})
}

}

angular.module('hermesApp').controller('QuestEditCtrl', QuestEditCtrl);
QuestEditCtrl.$inject = ['HermesService', '$q', '$routeParams', '$location'];
})();
3 changes: 3 additions & 0 deletions hermes/webapp/src/js/hermesApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
}).when('/v1/quest/new', {
templateUrl: '/templates/questCreation.html',
reloadOnSearch: false
}).when('/v1/quests/:questId/edit', {
templateUrl: '/templates/questEdit.html',
reloadOnSearch: false
}).when('/v1/labors/:laborId?', {
templateUrl: '/templates/laborList.html',
reloadOnSearch: false
Expand Down
32 changes: 32 additions & 0 deletions hermes/webapp/src/js/services/hermesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
getQuestCreatorThrowableEventTypes: getQuestCreatorThrowableEventTypes,
runQuery: runQuery,
createQuest: createQuest,
updateQuest: updateQuest,
createEvents: createEvents,
getServerConfig: getServerConfig
};
Expand Down Expand Up @@ -76,6 +77,37 @@
}
}

/**
* Update a given quest with new values
* @param questId the id of the quest to update
* @param fields hash of fields to update. Should only contain "owner", "description", and/or "targetTime"
*/
function updateQuest(questId, fields) {
var json = {};
if ("creator" in fields) {
json["creator"] = fields["creator"];
}
if ("description" in fields) {
json["description"] = fields["description"];
}
if ("targetTime" in fields) {
json["targetTime"] = fields["targetTime"];
}

return $http.put("/api/v1/quests/" + questId, json)
.then(updateQuestCompleted)
.catch(updateQuestFailed);

function updateQuestCompleted(response) {
return response;
}

function updateQuestFailed(error) {
console.error("API for updating a quest failed! " + error.status + " " + error.statusText);
throw error;
}
}

/**
* Try to create events for the given hsots
* @param user the authenticated user creating these events
Expand Down

0 comments on commit 33a0a5e

Please sign in to comment.