Skip to content

Commit

Permalink
Merge pull request #86 from diggyk/master
Browse files Browse the repository at this point in the history
Added new landing page
  • Loading branch information
jathanism committed Nov 4, 2015
2 parents f5c6f09 + 580ae1b commit cbd72ee
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 13 deletions.
6 changes: 3 additions & 3 deletions hermes/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ def get(self):
:query string hostname: (*optional*) filter Labors by a particular hostname
:query string startingLaborId: (*optional*) get Labors by the Id or the Id of the starting labor
:query string hostQuery: (*optional*) the query to send to the plugin to come up with the list of hostnames
:query string userQuery: (*optional*) get labors for machines ownen by this user or for which this user is responsible
:query string userQuery: (*optional*) get labors for machines owned by this user or for which this user is responsible
:query string category: (*optional*) limit labors to ones where the starting event type is of this category
:query string state: (*optional*) limit labors to ones where the starting event type is of this state
:query boolean open: if true, filter Labors to those still open
Expand Down Expand Up @@ -1618,9 +1618,9 @@ def get(self):
hostnames = list(
set(host_query_hostnames) & set(user_query_hostnames)
)
elif host_query_hostnames:
elif host_query:
hostnames = host_query_hostnames
elif user_query_hostnames:
elif user_query:
hostnames = user_query_hostnames

# if we are just doing a simple host_query, we can just filter by
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.5.1"
__version__ = "0.5.3"
49 changes: 49 additions & 0 deletions hermes/webapp/src/css/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,14 @@ a {
padding: 20px;
}
.dialog-callout {
font-size: 1.5em;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
background: @white;
border-radius: 5px;
margin: 10px;
padding: 10px;
text-align: center;
}
.dialog-buttons {
text-align: center;
Expand Down Expand Up @@ -903,4 +905,51 @@ a {
-webkit-transition-duration: 0s;
transition-delay: 0.05s;
transition-duration: 0s;
}

.user-home {
button {
padding: 20px;
float: none;
margin-top: 2em;
&.ng-enter {
margin-top: 3em;
opacity: 0;
-webkit-transition: 0.5s ease-out all;
-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;;
}
&.ng-enter-active {
margin-top: 2em;
opacity: 1;
}
}
.banner {
font-size: 3em;
text-align: center;
margin-top: 3em;
&.ng-enter {
margin-top: 2em;
opacity: 0;
-webkit-transition: 0.5s ease-out all;
-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;;
}
&.ng-enter-active {
margin-top: 3em;
opacity: 1;
}
}
.quest-info {
font-size: 1.5em;
text-align: center;
}
.labor-info {
font-size: 1.5em;
text-align: center;
}
}
2 changes: 1 addition & 1 deletion hermes/webapp/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">
<a class="navbar-brand" href="/">
<img alt="Brand" src="/img/logo.png">
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion hermes/webapp/src/js/controllers/questStatusCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

// if user passed a filter-by-creator query param, that takes precedence.
// otherwise, the default is to use the authenticate user
if ($routeParams.byCreator) {
if ($routeParams.byCreator || $routeParams.byCreator == "") {
vm.filterByCreator = $routeParams.byCreator;
vm.filterOwn = false;
} else if (vm.user && !$routeParams.questId) {
Expand Down
129 changes: 129 additions & 0 deletions hermes/webapp/src/js/controllers/userHomeCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
(function() {
'use strict';

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

vm.errorMessage = null;

vm.domain = null;
vm.user = null;
vm.questData = null;
vm.totalQuests = null;
vm.totalUserCreatedQuests = null;
vm.totalLabors = null;
vm.totalUserLabors = null;

vm.questsUrl = null;
vm.laborsUrl = null;

vm.goToQuestsPage = goToQuestsPage;
vm.goToLaborsPage = goToLaborsPage;

hermesService.getCurrentUser().then(function (user) {
if (user) {
vm.user = user;
}

// find labors and quests for this user
getOpenQuests();
getOpenLabors();
});

hermesService.getServerConfig().then(function(config) {
vm.domain = config['domain'];
});

function goToCreatePage() {
$location.url("/v1/quest/new");
}

function goToQuestsPage() {
$location.url(vm.questsUrl);
}

function goToLaborsPage() {
$location.url(vm.laborsUrl);
}

/**
* Get open quest information, but we only want basic overview information.
*/
function getOpenQuests() {
vm.errorMessage = null;

var options = {};
options['overviewOnly'] = true;

hermesService.getOpenQuests(options).then(function (questData) {
vm.questData = questData['quests'];
vm.totalQuests = questData['totalQuests'];

// see which quests are overdue and which are owned by this user
vm.totalUserCreatedQuests = 0;
for (var idx in vm.questData) {
evalDueDate(vm.questData[idx]);
if (vm.questData[idx]['creator'] == vm.user) {
vm.totalUserCreatedQuests++;
}
}

if (vm.totalUserCreatedQuests == 0) {
vm.questsUrl = "/v1/quests/?byCreator=";
} else {
vm.questsUrl = "/v1/quests?byCreator=" + vm.user;
}
});
}

/**
* Get labor information (overview only) for all open labors and labors
* that apply to this user.
*/
function getOpenLabors() {
var options = {};
options['overviewOnly'] = true;

hermesService.getOpenLabors(options).then(function (laborData){
vm.totalLabors = laborData['totalLabors'];
});

options['filterByOwner'] = vm.user;

hermesService.getOpenLabors(options).then(function (laborData) {
vm.totalUserLabors = laborData['totalLabors'];
vm.laborsUrl = "/v1/labors?byOwner=" + vm.user;
}).catch(function(error) {
vm.totalUserLabors = 0;
vm.laborsUrl = "/v1/labors?byOwner=";
});
}

/**
* Determine if the quest is overdue and add a property to indicate
* @param quest the quest to analyze
*/
function evalDueDate(quest) {
if (quest.targetTime) {
var dateRegex = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/;
var dateArray = dateRegex.exec(quest.targetTime);
var targetDate = new Date(
(+dateArray[1]),
(+dateArray[2]) - 1, // Careful, month starts at 0!
(+dateArray[3]),
(+dateArray[4]),
(+dateArray[5]),
(+dateArray[6])
);

if (targetDate - new Date() <= 0) quest.overDue = true;
else quest.overDue = false;
} else {
quest.overDue = false;
}
}
}

angular.module('hermesApp').controller('UserHomeCtrl', UserHomeCtrl);
UserHomeCtrl.$inject = ['HermesService', '$q', '$routeParams', '$location', 'smoothScroll'];
})();
5 changes: 4 additions & 1 deletion hermes/webapp/src/js/hermesApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
}).when('/v1/fates', {
templateUrl: '/templates/fateViewer.html',
reloadOnSearch: false
}).otherwise({redirectTo: '/v1/quests/'});
}).when('/home', {
templateUrl: '/templates/userHome.html',
reloadOnSearch: false
}).otherwise({redirectTo: '/home/'});

// use the HTML5 History API
$locationProvider.html5Mode({
Expand Down
15 changes: 13 additions & 2 deletions hermes/webapp/src/js/services/hermesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@
* Get a list of all open labors, along with quest details
*/
function getOpenLabors(options) {
var url = "/api/v1/labors/?open=true&expand=hosts&limit=all&expand=quests&expand=events&expand=eventtypes&expand=fates";

var url;
if (options['overviewOnly']) {
url = "/api/v1/labors/?open=true";
} else {
url = "/api/v1/labors/?open=true&expand=hosts&limit=all&expand=quests&expand=events&expand=eventtypes&expand=fates";
}

if (options['filterByOwner']) {
url += "&userQuery=" + encodeURIComponent(options['filterByOwner']);
Expand Down Expand Up @@ -148,7 +154,12 @@
*/
function getOpenQuests(options) {

var url = "/api/v1/quests?filterClosed=true&progressInfo=true&expand=hosts&expand=labors&limit=all";
var url;
if (options['overviewOnly']) {
url = "/api/v1/quests?filterClosed=true&progressInfo=true&limit=all"
} else {
url = "/api/v1/quests?filterClosed=true&progressInfo=true&expand=hosts&expand=labors&limit=all";
}

if (options['filterByCreator']) {
url += "&byCreator=" + encodeURIComponent(options['filterByCreator']);
Expand Down
2 changes: 1 addition & 1 deletion hermes/webapp/src/templates/laborList.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
</div>
<div ng-cloak class="modal-wrapper fade" ng-if="lsc.createEventsModal">
<div id="confirmModal" class="modal-dialog" role="dialog">
<div class="dialog-callout">The event <code>{{lsc.selectedEventType.category}} {{lsc.selectedEventType.state}}</code> means: {{lsc.selectedEventType.description}}</div>
<div class="dialog-callout">"{{lsc.selectedEventType.description}}"</code></div>
<div class="dialog-text">
Are you sure you want to create a <code>{{lsc.selectedEventType.category}} {{lsc.selectedEventType.state}}</code> event for {{lsc.selected.length}} servers?
</div>
Expand Down
5 changes: 2 additions & 3 deletions hermes/webapp/src/templates/questStatus.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,8 @@
</div>
<div ng-cloak class="modal-wrapper fade" ng-if="qc.createEventsModal">
<div id="confirmModal" class="modal-dialog" role="dialog">
<div class="dialog-callout">The event <code>{{qc.selectedEventType.category}}
{{qc.selectedEventType.state}}</code> means:
{{qc.selectedEventType.description}}
<div class="dialog-callout">
"{{qc.selectedEventType.description}}"
</div>
<div class="dialog-text">
Are you sure you want to create a <code>{{qc.selectedEventType.category}}
Expand Down
9 changes: 9 additions & 0 deletions hermes/webapp/src/templates/userHome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div ng-controller="UserHomeCtrl as ctrl" class="user-home">
<div class="row">
<div class="col-md-12 banner" ng-if="ctrl.user">Hello {{ctrl.user}}</div>
</div>
<div class="row">
<div class="col-md-3 col-md-offset-3 quest-info"><button ng-if="ctrl.totalQuests != null" ng-click="ctrl.goToQuestsPage()">{{ctrl.totalQuests}} total open quests.<br/>{{ctrl.totalUserCreatedQuests}} created by you.</button></div>
<div class="col-md-3 labor-info"><button ng-if="ctrl.totalUserLabors != null" ng-click="ctrl.goToLaborsPage()">{{ctrl.totalLabors}} total open labors.<br/>{{ctrl.totalUserLabors}} are for you.</button></div>
</div>
</div>

0 comments on commit cbd72ee

Please sign in to comment.