Skip to content

Commit

Permalink
Merge pull request #84 from diggyk/master
Browse files Browse the repository at this point in the history
Updating the fate's explorer to show fate desc
  • Loading branch information
mcot2 committed Nov 2, 2015
2 parents 2ec429f + 2a09383 commit 3f70aee
Show file tree
Hide file tree
Showing 19 changed files with 317 additions and 374 deletions.
7 changes: 4 additions & 3 deletions db/update_to_05.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ VALUES
(5,5,4, 1, 0, 'Maintenance completed');

ALTER TABLE `labors` ADD `fate_id` INT(11) NOT NULL DEFAULT 0 AFTER `starting_labor_id`;
ALTER TABLE `labors` ADD INDEX `ix_labors_fate_id` (`fate_id`);

UPDATE `labors` SET `fate_id`=1;
ALTER TABLE `labors` ADD FOREIGN KEY `ix_labors_fate_id` (`fate_id`) REFERENCES FATES(`id`);

ALTER TABLE `labors` ADD FOREIGN KEY (`fate_id`) REFERENCES `fates` (`id`);

UPDATE `labors` l
SET `fate_id` = (
Expand All @@ -38,4 +38,5 @@ SET `fate_id` = (

INSERT INTO fates
VALUES
(6,4,1, 0, 1, 'A release finishes labors');
(6,4,1, 0, 1, 'A release finishes labors');

70 changes: 70 additions & 0 deletions db/update_to_051.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
SET foreign_key_checks=0;
DROP TABLE IF EXISTS event_types;

CREATE TABLE event_types (
id int(11) NOT NULL AUTO_INCREMENT,
category varchar(64) COLLATE utf8_unicode_ci NOT NULL,
state varchar(32) COLLATE utf8_unicode_ci NOT NULL,
description varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY _category_state_uc (category,state),
KEY event_type_idx (id,category,state)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

LOCK TABLES event_types WRITE;
/*!40000 ALTER TABLE event_types DISABLE KEYS */;

INSERT INTO event_types (id, category, state, description)
VALUES
(1,'system-reboot','required','System requires a reboot'),
(2,'system-reboot','completed','System rebooted'),
(3,'system-maintenance','required','System requires maintenance'),
(4,'system-maintenance','ready','System ready for maintenance'),
(5,'system-maintenance','completed','System maintenance completed'),
(6,'system-maintenance','acknowledge','Acknowledge system maintenance'),
(7,'system-maintenance','cancel','Cancel system maintenance');

/*!40000 ALTER TABLE event_types ENABLE KEYS */;
UNLOCK TABLES;


# Dump of table fates
# ------------------------------------------------------------

DROP TABLE IF EXISTS fates;

CREATE TABLE fates (
id int(11) NOT NULL AUTO_INCREMENT,
creation_type_id int(11) NOT NULL,
follows_id int(11) DEFAULT NULL,
for_creator int(1) NOT NULL DEFAULT '0',
for_owner int(1) NOT NULL DEFAULT '1',
description varchar(2048) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY _creation_completion_uc (creation_type_id,follows_id),
KEY ix_fates_creation_type_id (creation_type_id),
KEY fate_idx (id,creation_type_id,follows_id),
KEY ix_fates_follows_id (follows_id),
CONSTRAINT fates_ibfk_1 FOREIGN KEY (creation_type_id) REFERENCES event_types (id),
CONSTRAINT fates_ibfk_3 FOREIGN KEY (follows_id) REFERENCES fates (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

LOCK TABLES fates WRITE;
/*!40000 ALTER TABLE fates DISABLE KEYS */;

INSERT INTO fates (id, creation_type_id, follows_id, for_creator, for_owner, description)
VALUES
(1,1,NULL,0,1,'Reboot or release the system'),
(2,2,1,0,1,'System rebooted'),
(3,3,NULL,0,1,'Release or acknowledge downtime'),
(4,4,3,0,1,'Perform maintenance'),
(5,5,4,1,0,'Maintenance completed'),
(6,6,3,0,1,'Acknowledge maintenance'),
(7,5,6,1,0,'Maintenance completed'),
(8,7,3,0,1,'Maintenance cancelled'),
(9,7,4,0,1,'Maintenance cancelled'),
(10,7,6,0,1,'Maintenance cancelled');

/*!40000 ALTER TABLE fates ENABLE KEYS */;
UNLOCK TABLES;
SET foreign_key_checks=1;
4 changes: 0 additions & 4 deletions hermes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,6 @@ def to_dict(self, base_uri=None, expand=None):
fate.to_dict(base_uri=base_uri, expand=set(expand))
for fate in self.auto_creates
]
out['autoCompletes'] = [
fate.to_dict(base_uri=base_uri, expand=set(expand))
for fate in self.auto_completes
]

if base_uri:
out['href'] = self.href(base_uri)
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.0"
__version__ = "0.5.1"
1 change: 0 additions & 1 deletion hermes/webapp/src/css/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ a {
-webkit-border-radius: 5px 0px 0px 0px;
border-radius: 5px 0px 0px 0px;
font-size: 1.0em;
font-weight: bold;
padding: 2px 5px;
}
.labor-type {
Expand Down
74 changes: 54 additions & 20 deletions hermes/webapp/src/js/controllers/fateCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@
function redrawGraph() {
vm.paper.clear();

var graphSet = vm.paper.set();

var svg = document.querySelector("svg");
svg.removeAttribute("width");
svg.removeAttribute("height");

// we declare our settings here so they can be changed dynamically as needed
var settings = {
'xScale': 600,
'xOffset': 100,
'yScale': 500,
'yOffset': 140,
'yOffset': 90,
'padding': 20,
'rootNodeStyle': {
'fill': "#000"
},
Expand All @@ -64,7 +71,7 @@
for (var idx in vm.graphData.edges) {
var edge = vm.graphData.edges[idx];

drawEdge(vm.paper, settings, edge);
drawEdge(vm.paper, settings, edge, graphSet);
}

// draw our nodes
Expand All @@ -73,31 +80,32 @@
switch (node["type"]) {
case "rootNode":
drawRootNode(
vm.paper, settings, node
vm.paper, settings, node, graphSet
);
break;
case "childNode":
drawChildNode(
vm.paper, settings, node
vm.paper, settings, node, graphSet
);
break;
case "endNode":
drawEndNode(
vm.paper, settings, node
vm.paper, settings, node, graphSet
);
break;
}

addNodeLabel(vm.paper, settings, node);
addNodeLabel(vm.paper, settings, node, graphSet);
}

vm.paper.setViewBox(0, 0, vm.paper.width + 500, vm.paper.height + 500, true);
vm.panZoom = vm.paper.panzoom({
initialZoom: 1,
initialPosition: { x: 0, y: 0},
maxZoom: 1,
});
vm.panZoom.enable();
var paperBox = graphSet.getBBox();
var xPad = paperBox.x - settings['padding'];
var yPad = paperBox.y - settings['padding'];

vm.paper.setViewBox(xPad, yPad, paperBox.width + (settings['padding'] * 2),
paperBox.height + (settings['padding'] * 2), true);
vm.paper.setSize(paperBox.width + (settings['padding'] * 2),
paperBox.height + (settings['padding'] * 2));
}

/**
Expand All @@ -107,13 +115,15 @@
* @param style the style to use for this node
* @param node the node to draw
*/
function drawRootNode(paper, settings, node) {
function drawRootNode(paper, settings, node, graphSet) {

var x = node['x'] * settings['xScale'] + settings['xOffset'];
var y = node['y'] * settings['yScale'] + settings['yOffset'];

var circle = paper.circle(x, y, 8);
circle.attr({'fill': '#000'});

graphSet.push(circle);
}

/**
Expand All @@ -123,12 +133,13 @@
* @param style the style to use for this node
* @param node the node to draw
*/
function drawChildNode(paper, settings, node) {
function drawChildNode(paper, settings, node, graphSet) {
var x = node['x'] * settings['xScale'] + settings['xOffset'];
var y = node['y'] * settings['yScale'] + settings['yOffset'];

var circle = paper.circle(x, y, 8);
circle.attr({'fill': '#000'});
graphSet.push(circle);

var circle2 = paper.circle(x, y, 6);
circle2.attr({ 'fill': '#fff'});
Expand All @@ -141,12 +152,13 @@
* @param style the style to use for this node
* @param node the node to draw
*/
function drawEndNode(paper, settings, node) {
function drawEndNode(paper, settings, node, graphSet) {
var x = node['x'] * settings['xScale'] + settings['xOffset'];
var y = node['y'] * settings['yScale'] + settings['yOffset'];

var circle = paper.circle(x, y, 8);
circle.attr({'fill': '#000'});
graphSet.push(circle);

var circle2 = paper.circle(x, y, 6);
circle2.attr({ 'fill': '#fff'});
Expand All @@ -161,13 +173,34 @@
* @param settings the settings to use
* @param node the node to label
*/
function addNodeLabel(paper, settings, node) {
function addNodeLabel(paper, settings, node, graphSet) {
var x = node['x'] * settings['xScale'] + settings['xOffset'];
var y = node['y'] * settings['yScale'] + settings['yOffset'] - 32;
var label = paper.text(x, y, node["label"].replace(' ', '\n'));
var label = paper.text(x, y, node["label"]);


var maxWidth = (settings['xScale'] / 2);
// do some word wrapping here by testing the bounding box

var labelWords = node['label'].replace(/(\r\n|\n|\r)/gm, '').split(" ");
var wrappedText = '';
for (var idx in labelWords) {
label.attr("text", wrappedText + " " + labelWords[idx]);
if (label.getBBox().width > maxWidth) {
wrappedText += '\n' + labelWords[idx];
} else {
wrappedText += ' ' + labelWords[idx];
}
}
label.attr({
'font-size': 16,
});
var bb = label.getBBox();
var h = Math.abs(bb.y2) - Math.abs(bb.y);
label.attr({
'y': node['y'] * settings['yScale'] + settings['yOffset'] - 16 - (h/2)
});
graphSet.push(label);
}

/**
Expand All @@ -176,9 +209,10 @@
* @param settings our settings
* @param edge the edge we want to draw
*/
function drawEdge(paper, settings, edge) {
function drawEdge(paper, settings, edge, graphSet) {
var node1 = getNodeById(edge['source']);
var node2 = getNodeById(edge['target']);
console.log(node2);
if (!node1 || !node2) {
return;
}
Expand All @@ -192,7 +226,7 @@
var pathStr = "M" + x1 + "," + y1
+ " C" + (x1 + indent) + "," + y1 + "," + x1 + "," + y2 + "," + (x1 + indent) + "," + y2
+ " L" + x2 + "," + y2;
paper.path(pathStr).attr({'stroke': '#000'});
graphSet.push(paper.path(pathStr).attr({'stroke': '#000'}));

addEdgeLabel(paper, settings, edge, (x1 + indent), y2);
}
Expand Down
31 changes: 19 additions & 12 deletions hermes/webapp/src/js/controllers/laborStatusCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
vm.errorMessage = null;
vm.hostOwnerInput = null;
vm.filterOwn = false;
vm.fates = false;
vm.queryInput = null;
vm.filterEventType = null;
vm.filterFate = null;
vm.selectedEventType = null;

vm.laborData = null;
Expand All @@ -17,6 +18,7 @@
vm.hostOwners = null;
vm.throwableTypes = null;
vm.allTypes = null;
vm.allFates = null;
vm.createInProgress = false;
vm.limit = 10;
vm.offset = 0;
Expand All @@ -34,7 +36,7 @@
vm.deselectAll = deselectAll;
vm.filterOwnChanged = filterOwnChanged;
vm.throwableEventTypesSelection = throwableEventTypesSelection;
vm.filterEventTypesSelection = filterEventTypesSelection;
vm.filterFatesSelection = filterFatesSelection;
vm.createEvents = createEvents;


Expand Down Expand Up @@ -72,10 +74,15 @@
vm.queryInput = $routeParams.byQuery;
}

hermesService.getAllEventTypes().then(function(types) {
var allTypes = [null];
vm.allTypes = allTypes.concat(types);
vm.filterEventType = vm.allTypes[0];
hermesService.getFates().then(function(fates) {
vm.allFates = [null];
for (var idx in fates) {
if (fates[idx].precedesIds.length != 0) {
vm.allFates.push(fates[idx]);
}
}
vm.filterFate = vm.allFates[0];
vm.fates = fates;
});

hermesService.getUserThrowableEventTypes().then(function(types) {
Expand Down Expand Up @@ -183,11 +190,11 @@
}
}

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

Expand Down Expand Up @@ -231,9 +238,9 @@
$location.search('byQuery', null, false);
}

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

hermesService.getOpenLabors(options).then(function (data) {
Expand Down

0 comments on commit 3f70aee

Please sign in to comment.