-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added base code for the eos model plugin #486
- Loading branch information
Matthew Letter
committed
Sep 17, 2015
1 parent
69bf1bf
commit 2ebef1b
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
def register_slycat_plugin(context): | ||
import os | ||
|
||
def finish(database, model): | ||
import datetime | ||
import slycat.web.server | ||
slycat.web.server.update_model(database, model, state="finished", result="succeeded", finished=datetime.datetime.utcnow().isoformat(), progress=1.0, message="") | ||
|
||
def html(database, model): | ||
name = model["artifact:name"] | ||
return """ | ||
<div style="-webkit-flex:1;flex:1;display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;padding:12px; text-align:center; font-weight: bold; font-size: 36px;"> | ||
<p>Hello, %s!</p> | ||
</div>""" % name | ||
|
||
# Register the new model. | ||
context.register_model("eos", finish) | ||
|
||
# Register a default page for displaying the model. | ||
context.register_page("eos", html) | ||
|
||
# Register a wizard for creating instances of the new model. | ||
context.register_wizard("eos", "New EOS Model", require={"action":"create", "context":"project"}) | ||
context.register_wizard_resource("eos", "ui.js", os.path.join(os.path.dirname(__file__), "ui.js")) | ||
context.register_wizard_resource("eos", "ui.html", os.path.join(os.path.dirname(__file__), "ui.html")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<div class="modal-header"> | ||
<h3 class="modal-title">New Hello World Model</h3> | ||
</div> | ||
<div class="modal-body"> | ||
<ul class="nav nav-pills"> | ||
<li data-bind="css:{active:tab() == 0}"><a>Name Model</a></li> | ||
<li data-bind="css:{active:tab() == 1}"><a>Choose Recipient</a></li> | ||
<li data-bind="css:{active:tab() == 2}"><a>Results</a></li> | ||
</ul> | ||
|
||
<div class="tab-content"> | ||
<div data-bind="visible:tab() == 0"> | ||
<form class="form-horizontal"> | ||
<slycat-model-controls params="name:model.name,description:model.description,marking:model.marking"></slycat-model-controls> | ||
</form> | ||
</div> | ||
<div data-bind="visible:tab() == 1"> | ||
<form class="form-horizontal"> | ||
<div class="form-group"> | ||
<label for="recipient" class="col-sm-2 control-label">Recipient</label> | ||
<div class="col-sm-10"> | ||
<input type="text" id="recipient" class="form-control" data-bind="value:recipient"> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
<div data-bind="visible:tab() == 2"> | ||
<slycat-model-results params="{mid : model._id}"></slycat-model-results> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button class="btn btn-default pull-left" data-bind="visible:tab() != 2" data-dismiss="modal">Cancel</button> | ||
<button class="btn btn-default" data-bind="visible:tab() == 0,click:create">Continue</button> | ||
<button class="btn btn-default" data-bind="visible:tab() == 1,click:finish">Finish</button> | ||
<button class="btn btn-default pull-left" data-bind="visible:tab() == 2" data-dismiss="modal">Close</button> | ||
<button class="btn btn-default" data-bind="visible:tab() == 2,click:go_to_model">Go To Model</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
define(["slycat-server-root", "slycat-web-client", "slycat-dialog", "knockout", "knockout-mapping"], function(server_root, client, dialog, ko, mapping) | ||
{ | ||
function constructor(params) | ||
{ | ||
var component = {}; | ||
component.tab = ko.observable(0); | ||
component.project = params.projects()[0]; | ||
component.model = mapping.fromJS({_id: null, name: "New EOS Model", description: "", marking: null}); | ||
component.recipient = ko.observable("EOS"); | ||
|
||
component.create = function() | ||
{ | ||
component.tab(1); | ||
}; | ||
|
||
component.go_to_model = function() { | ||
location = server_root + 'models/' + component.model._id(); | ||
}; | ||
|
||
component.finish = function() | ||
{ | ||
client.post_project_models( | ||
{ | ||
pid: component.project._id(), | ||
type: "eos", | ||
name: component.model.name(), | ||
description: component.model.description(), | ||
marking: component.model.marking(), | ||
success: function(mid) | ||
{ | ||
component.model._id(mid); | ||
|
||
client.put_model_parameter( | ||
{ | ||
mid: component.model._id(), | ||
aid: "name", | ||
value: component.recipient(), | ||
input: true, | ||
success: function() | ||
{ | ||
client.post_model_finish( | ||
{ | ||
mid: component.model._id(), | ||
success: function() | ||
{ | ||
component.tab(2); | ||
} | ||
}); | ||
} | ||
}); | ||
}, | ||
error: dialog.ajax_error("Error creating model.") | ||
}); | ||
}; | ||
return component; | ||
} | ||
|
||
return { | ||
viewModel: constructor, | ||
template: { require: "text!" + server_root + "resources/wizards/hello-world/ui.html" } | ||
}; | ||
}); |