Skip to content

Commit

Permalink
Merge pull request #49 from diggyk/master
Browse files Browse the repository at this point in the history
Added query and user filtering
  • Loading branch information
jathanism committed Sep 22, 2015
2 parents ed61772 + af70dd7 commit 40c3d2b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 21 deletions.
15 changes: 12 additions & 3 deletions hermes/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ def get(self):
.order_by(desc(Labor.creation_time))
)

hostnames = []
host_query_hostnames = []
if host_query:
response = PluginHelper.request_get(params={"query": host_query})
if (
Expand All @@ -1557,21 +1557,30 @@ def get(self):
):
# FIXME -- couldn't this just be hostnames.extend?
for hostname in response.json()["results"]:
hostnames.append(hostname)
host_query_hostnames.append(hostname)
else:
raise exc.BadRequest("Bad host query: {}".format(host_query))

user_query_hostnames = []
if user_query:
response = PluginHelper.request_get(params={"user": user_query})
if (
response.status_code == 200
and response.json()["status"] == "ok"
):
for hostname in response.json()["results"]:
hostnames.append(hostname)
user_query_hostnames.append(hostname)
else:
raise exc.BadRequest("Bad user query: {}".format(user_query))

hostnames = []
if host_query and user_query:
hostnames = list(set(host_query_hostnames) & set(user_query_hostnames))
elif host_query_hostnames:
hostnames = host_query_hostnames
elif user_query_hostnames:
hostnames = user_query_hostnames;

if host_query or user_query:
if hostnames:
hosts = (
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.4.0"
__version__ = "0.4.1"
46 changes: 33 additions & 13 deletions hermes/webapp/src/js/controllers/laborStatusCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
vm.errorMessage = null;
vm.hostOwnerInput = null;
vm.queryInput = null;
vm.filterEventType = null;
vm.selectedEventType = null;

vm.laborData = null;
vm.selected = [];
vm.hostTags = null;
vm.throwableTypes = null;
vm.allTypes = null;
vm.createInProgress = false;
vm.limit = 10;
vm.offset = 0;
Expand All @@ -28,7 +30,8 @@
vm.toggleSelect = toggleSelect;
vm.selectAll = selectAll;
vm.deselectAll = deselectAll;
vm.eventTypesSelection = eventTypesSelection;
vm.throwableEventTypesSelection = throwableEventTypesSelection;
vm.filterEventTypesSelection = filterEventTypesSelection;
vm.createEvents = createEvents;


Expand All @@ -38,6 +41,11 @@
allowInvalid: true
};


if ($routeParams.byQuery) {
vm.queryInput = $routeParams.byQuery;
}

// if user passed a filter-by-owner query param, that takes precedence.
// otherwise, the default is to use the authenticate user
if ($routeParams.byOwner) {
Expand All @@ -48,18 +56,24 @@
if (user) {
vm.hostOwnerInput = user;
}
getOpenLabors("owner");
getOpenLabors();
});
}

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

hermesService.getAllEventTypes().then(function(types) {
var allTypes = [""];
vm.allTypes = allTypes.concat(types);
vm.filterEventType = vm.allTypes[0];
});

hermesService.getUserThrowableEventTypes().then(function(types) {
vm.throwableTypes = types;
vm.selectedEventType = vm.throwableTypes[0];
Expand Down Expand Up @@ -114,42 +128,48 @@
/**
* The getter/setter for event types
*/
function eventTypesSelection(selection) {
function throwableEventTypesSelection(selection) {
if (angular.isDefined(selection)) {
vm.selectedEventType = selection;
} else {
return vm.selectedEventType;
}
}

function filterEventTypesSelection(selection) {
if (angular.isDefined(selection)) {
vm.filterEventType = selection;
} else {
return vm.filterEventType;
}
}

function runQueryFilter() {
$routeParams.laborId = null;
vm.offset = 0;
vm.hostOwnerInput = null;
getOpenLabors("query");
getOpenLabors();
}

function runOwnerFilter() {
$routeParams.laborId = null;
vm.offset = 0;
vm.queryInput = null;
getOpenLabors("owner");
getOpenLabors();
}

function getOpenLabors(method) {
function getOpenLabors() {
vm.errorMessage = null;
vm.selected = [];
vm.laborData = null;

var options = {};
if (method == "owner" && vm.hostOwnerInput) {

if (vm.hostOwnerInput) {
options['filterByOwner'] = vm.hostOwnerInput;
$location.search('byOwner', vm.hostOwnerInput, false);
$location.search('byQuery', null, false);
} else if (method == "query" && vm.queryInput) {
}

if (vm.queryInput) {
options['filterByQuery'] = vm.queryInput;
$location.search('byOwner', null, false);
$location.search('byQuery', vm.queryInput, false);
}

Expand Down
23 changes: 20 additions & 3 deletions hermes/webapp/src/js/services/hermesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
getOwnerInformation: getOwnerInformation,
getHostTags: getHostTags,
getCurrentUser: getCurrentUser,
getAllEventTypes: getAllEventTypes,
getStartingEventTypes: getStartingEventTypes,
getUserThrowableEventTypes: getUserThrowableEventTypes,
getQuestCreatorThrowableEventTypes: getQuestCreatorThrowableEventTypes,
Expand Down Expand Up @@ -105,11 +106,11 @@
function getOpenLabors(options) {
var url = "/api/v1/labors/?open=true&expand=hosts&limit=all&expand=quests&expand=events&expand=eventtypes";

console.log("getOpenLabors:");
console.log(options);
if (options['filterByOwner']) {
url += "&userQuery=" + options['filterByOwner'];
} else if (options['filterByQuery']) {
}

if (options['filterByQuery']) {
url += "&hostQuery=" + options['filterByQuery'];
}

Expand Down Expand Up @@ -429,6 +430,22 @@
}
}

function getAllEventTypes() {
return $http.get("/api/v1/eventtypes?limit=all")
.then(getCompleted)
.catch(getFailed);

function getCompleted(response) {
return response.data.eventTypes;
}

function getFailed(error) {
console.error("API call to get all event-types failed. "
+ error.status + " " + error.statusText);
throw error;
}
}

/**
* Get all event-types that quest creators are allowed to throw. Basically,
* this is any event-type of state "completed."
Expand Down
21 changes: 20 additions & 1 deletion hermes/webapp/src/templates/laborList.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
<button ng-click="lsc.runQueryFilter()">GO</button>
</div>
</div>
<!--<div style="margin-top: 5px">-->
<!--Filter by labor's event type:-->
<!--</div>-->
<!--<div class="row">-->
<!--<select ng-model="lsc.filterEventTypesSelection"-->
<!--ng-model-options="lsc.selectOptions"-->
<!--ng-options="optValue.category + ' ' + optValue.state for optValue in lsc.allTypes">-->
<!--</select>-->
<!--</div>-->
<div ng-if="lsc.laborData && !lsc.errorMessage" style="padding: 5px 0px 5px 0px">
<label>
Limit:
Expand All @@ -54,7 +63,7 @@
<div class="labor-list-wrapper">
<div class="labor-actions"
ng-class="lsc.selected.length == 0 ? 'disabled' : ''">
Throw <select ng-model="lsc.eventTypesSelection"
Throw <select ng-model="lsc.throwableEventTypesSelection"
ng-model-options="lsc.selectOptions"
ng-options="optValue.category + ' ' + optValue.state for optValue in lsc.throwableTypes">
</select> for {{lsc.selected.length}} selected hosts.
Expand Down Expand Up @@ -108,6 +117,16 @@
</div>
</div>
</div>
<div ng-if="lsc.laborData && !lsc.errorMessage" class="labor-left-panel-page-selector">
<strong>Page:</strong>
<ul>
<li ng-click="lsc.pageSetting(pageVal)"
ng-repeat="pageVal in lsc.pageValues()"
ng-class="(lsc.pageSetting() == pageVal) ? 'selected' : ''">
{{pageVal}}
</li>
</ul>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 40c3d2b

Please sign in to comment.