Skip to content

Commit

Permalink
Merge pull request #50 from diggyk/master
Browse files Browse the repository at this point in the history
Added filter by event type
  • Loading branch information
jathanism committed Sep 22, 2015
2 parents 40c3d2b + d77ce00 commit 12f797d
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 50 deletions.
19 changes: 19 additions & 0 deletions hermes/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,8 @@ def get(self):
: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*) the user query to send to the plugin to come up with the list of hostnames
: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
:query int questId: the id of the quest we want to filter by
:query string expand: (*optional*) supports hosts, eventtypes, events, quests
Expand All @@ -1516,9 +1518,26 @@ def get(self):
quest_id = self.get_argument("questId", None)
host_query = self.get_argument("hostQuery", None)
user_query = self.get_argument("userQuery", None)
category = self.get_argument("category", None)
state = self.get_argument("state", None)

labors = self.session.query(Labor)

if category or state:
event_types = self.session.query(EventType);
if category:
event_types = event_types.filter(
EventType.category == category
)
if state:
event_types = event_types.filter(
EventType.state == state
)
valid_event_types = [event_type.id for event_type in event_types]
labors = labors.join(Labor.creation_event).join(Event.event_type).filter(
EventType.id.in_(valid_event_types)
)

if open_flag and open_flag.lower() == "true":
labors = labors.filter(Labor.completion_event_id == None)
if open_flag and open_flag.lower() == "false":
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.1"
__version__ = "0.4.2"
27 changes: 13 additions & 14 deletions hermes/webapp/src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ button:hover {
-moz-border-radius: 0px;
border-radius: 0px;
height: 60px;
box-shadow: 0px 0px 20px #000000;
box-shadow: 0px 0px 8px #000000;
}

.navbar-collapse, .navbar-brand {
Expand All @@ -106,12 +106,12 @@ button:hover {
-moz-border-radius: 5px 5px 0px 0px;
border-radius: 5px 5px 0px 0px;
border-bottom: 5px #25282b solid;
color: #7b8994;
color: #d0d4d9 !important;
}

.navbar-nav li a:hover, .navbar-nav li a:focus {
border-bottom-color: #004c8a;
color: #d0d4d9 !important;
color: #ffffff !important;
}

.navbar-nav > .active > a {
Expand Down Expand Up @@ -519,16 +519,12 @@ button:hover {
border-radius: 0px 5px 0px 0px;
}

.labor-list-wrapper .labor-entry .panel-label {
padding-left: 5px;
}

.labor-list-wrapper .labor-entry .tags {
.labor-list-wrapper .labor-entry .info-panel {
padding: 5px;
font-size: 0.9em;
}

.labor-list-wrapper .labor-entry .tags ul {
.labor-list-wrapper .labor-entry .info-panel ul {
display: block;
margin: 2px 0px;
padding: 5px;
Expand All @@ -538,17 +534,20 @@ button:hover {
background: #ffffff;
}

.labor-list-wrapper .labor-entry .tags li {
.labor-list-wrapper .labor-entry .info-panel li {
display: inline-block;
padding: 2px 5px;
}

.labor-list-wrapper .labor-entry .quest-info {
padding: 5px;
font-size: 0.9em;
.labor-list-wrapper .labor-entry .info-panel .label {
padding-left: 5px;
font-size: 1em;
font-weight: bold;
color: #000000;
margin-bottom: 4px;
}

.labor-list-wrapper .labor-entry .quest-info-details {
.labor-list-wrapper .labor-entry .info-panel .details {
margin: 2px 0px;
padding: 5px;
-webkit-border-radius: 5px;
Expand Down
25 changes: 15 additions & 10 deletions hermes/webapp/src/js/controllers/laborStatusCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
vm.laborData = null;
vm.selected = [];
vm.hostTags = null;
vm.hostOwners = null;
vm.throwableTypes = null;
vm.allTypes = null;
vm.createInProgress = false;
Expand All @@ -24,8 +25,7 @@

vm.colors = ['#0071ce', '#72b6ec', '#cce6fa', '#f4faff'];

vm.runOwnerFilter = runOwnerFilter;
vm.runQueryFilter = runQueryFilter;
vm.runFilter = runFilter;
vm.getOpenLabors = getOpenLabors;
vm.toggleSelect = toggleSelect;
vm.selectAll = selectAll;
Expand Down Expand Up @@ -69,7 +69,7 @@
});

hermesService.getAllEventTypes().then(function(types) {
var allTypes = [""];
var allTypes = [null];
vm.allTypes = allTypes.concat(types);
vm.filterEventType = vm.allTypes[0];
});
Expand Down Expand Up @@ -144,13 +144,7 @@
}
}

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

function runOwnerFilter() {
function runFilter() {
$routeParams.laborId = null;
vm.offset = 0;
getOpenLabors();
Expand All @@ -173,6 +167,11 @@
$location.search('byQuery', vm.queryInput, false);
}

if (vm.filterEventType) {
options['filterByCategory'] = vm.filterEventType.category;
options['filterByState'] = vm.filterEventType.state;
}

hermesService.getOpenLabors(options).then(function (data) {
if (!data
|| !data['labors']
Expand Down Expand Up @@ -218,6 +217,12 @@
vm.errorMessage = "Could not load host tags: " + error.statusText;
});

hermesService.getOwnerInformation(hostnames).then(function(data) {
vm.hostOwners = data;
}).catch(function(error) {
vm.errorMessage = "Could not load host owners: " + error.statusText;
})

}

/**
Expand Down
8 changes: 8 additions & 0 deletions hermes/webapp/src/js/services/hermesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@
url += "&hostQuery=" + options['filterByQuery'];
}

if (options['filterByCategory']) {
url += "&category=" + options['filterByCategory']
}

if (options['filterByState']) {
url += "&state=" + options['filterByState']
}

return $http.get(url)
.then(getLaborsComplete)
.catch(getLaborsFailed);
Expand Down
54 changes: 31 additions & 23 deletions hermes/webapp/src/templates/laborList.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,35 @@
</div>
<div class="row">
<div class="col-md-10">
<form ng-submit="lsc.runOwnerFilter()">
<form ng-submit="lsc.runFilter()">
<input id="ownerFilter" type="text" ng-model="lsc.hostOwnerInput" />
</form>
</div>
<div class="col-md-2">
<button ng-click="lsc.runOwnerFilter()">GO</button>
</div>
</div>
<div style="margin-top: 5px">
<label for="queryFilter">Filter by query:</label>
</div>
<div class="row">
<div class="col-md-10">
<form ng-submit="lsc.runQueryFilter()">
<form ng-submit="lsc.runFilter()">
<input id="queryFilter" type="text" ng-model="lsc.queryInput" />
</form>
</div>
</div>
<div style="margin-top: 5px">
<label for="event-type-selection">Filter by labor's event type:</label>
</div>
<div class="row">
<div class="col-md-10">
<select style="margin-left: 0" id="event-type-selection" ng-model="lsc.filterEventTypesSelection"
ng-model-options="lsc.selectOptions"
ng-options="optValue.category + ' ' + optValue.state for optValue in lsc.allTypes">
</select>
</div>
<div class="col-md-2">
<button ng-click="lsc.runQueryFilter()">GO</button>
<button ng-click="lsc.runFilter()">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 Down Expand Up @@ -95,8 +94,8 @@
<div class="labor-type col-md-6">{{labor.creationEvent.eventType.category}} {{labor.creationEvent.eventType.state}}</div>
</div>
<div class="row">
<div class="tags col-md-6">
<strong class="panel-label">Tags:</strong>
<div class="info-panel col-md-6">
<strong class="label">Tags:</strong>
<div>
<img ng-if="!lsc.hostTags" src="/img/loading_15.gif" alt="Tag information loading" />
<ul ng-if="lsc.hostTags">
Expand All @@ -106,13 +105,22 @@
</ul>
</div>
</div>
<div class="quest-info col-md-6"><strong class="panel-label">Quest Info:</strong>
<div class="quest-info-details" ng-if="labor.quest">
<strong>Quest {{labor.quest.id}}: </strong>
{{labor.quest.description}}
<div class="info-panel col-md-6">
<strong class="label">Owner:</strong>
<div class="details">
<img ng-if="!lsc.hostOwners" src="/img/loading_15.gif" alt="Owner information loading" />
<span ng-if="lsc.hostOwners">{{lsc.hostOwners[labor.host.hostname]}}</span>
</div>
<div class="quest-info-details" ng-if="!labor.quest">
Labor not part of a quest.
</div>
<div class="row" ng-if="labor.quest">
<div class="info-panel col-md-12"><strong class="label">Quest Info:</strong>
<div class="details">
<strong>Quest {{labor.quest.id}}: </strong>
{{labor.quest.description}}
</div>
<div class="details" ng-if="!labor.quest">
Labor not part of a quest.
</div>
</div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion hermes/webapp/src/templates/questCreation.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
<div class="row">
<div class="col-md-6 create-panel">
<div><label for="description">With description:</label>
<textarea id="description" ng-model="qc.description" />
<textarea id="description" ng-model="qc.description">

</textarea>
</div>
</div>
<div class="col-md-4 helper-panel">
Expand Down
79 changes: 78 additions & 1 deletion tests/api_tests/test_labors.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,81 @@ def test_update(sample_data1_server):
strip=["creationTime", "ackTime"]
)

assert response.json()['ackTime'] is not None
assert response.json()['ackTime'] is not None

def test_labor_filter_by_eventttype(sample_data1_server):
client = sample_data1_server

assert_success(
client.get("/labors"),
{
"limit": 10,
"offset": 0,
"totalLabors": 0,
"labors": []
}
)

# create a quest without a target_time
assert_created(
client.create(
"/quests",
creator="johnny",
eventTypeId=1,
description="This is a quest almighty",
hostnames=["example", "sample", "test"]
),
"/api/v1/quests/1"
)

# create a quest without a target_time
assert_created(
client.create(
"/quests",
creator="johnny",
eventTypeId=3,
description="This is a 2nd quest almighty",
hostnames=["example", "sample", "test"]
),
"/api/v1/quests/2"
)

assert_success(
client.get("/labors"),
{
"limit": 10,
"offset": 0,
"totalLabors": 6,
},
strip=["labors"]
)

assert_success(
client.get("/labors?hostname=example"),
{
"limit": 10,
"offset": 0,
"totalLabors": 2
},
strip=["labors"]
)

assert_success(
client.get("/labors?category=system-reboot&state=required"),
{
"limit": 10,
"offset": 0,
"totalLabors": 3
},
strip=["labors"]
)

assert_success(
client.get("/labors?category=system-maintenance"),
{
"limit": 10,
"offset": 0,
"totalLabors": 3
},
strip=["labors"]
)

0 comments on commit 12f797d

Please sign in to comment.