Move workflowengine to compiled handlebars

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-10-15 14:55:25 +02:00
parent e36d4a990d
commit 8c4c4b700f
No known key found for this signature in database
GPG Key ID: F941078878347C0C
7 changed files with 181 additions and 72 deletions

View File

@ -107,30 +107,13 @@
* Y8P 888 "Y8888 "Y8888888P" 88888P'
*/
/**
* @class OCA.WorkflowEngine.TemplateView
*
* a generic template that handles the Handlebars template compile step
* in a method called "template()"
*/
OCA.WorkflowEngine.TemplateView =
OC.Backbone.View.extend({
_template: null,
template: function(vars) {
if (!this._template) {
this._template = Handlebars.compile($(this.templateId).html());
}
return this._template(vars);
}
});
/**
* @class OCA.WorkflowEngine.OperationView
*
* this creates the view for a single operation
*/
OCA.WorkflowEngine.OperationView =
OCA.WorkflowEngine.TemplateView.extend({
OC.Backbone.View.extend({
templateId: '#operation-template',
events: {
'change .check-class': 'checkChanged',
@ -150,6 +133,18 @@
errorMessage: '',
saving: false,
groups: [],
template: function(vars) {
return OCA.WorkflowEngine.Templates['operation'](_.extend(
{
shortRuleDescTXT: t('workflowengine', 'Short rule description'),
addRuleTXT: t('workflowengine', 'Add rule'),
resetTXT: t('workflowengine', 'Reset'),
saveTXT: t('workflowengine', 'Save'),
savingTXT: t('workflowengine', 'Saving…')
},
vars
));
},
initialize: function() {
// this creates a new copy of the object to definitely have a new reference and being able to reset the model
this.originalModel = JSON.parse(JSON.stringify(this.model));
@ -354,13 +349,21 @@
* this creates the view for configured operations
*/
OCA.WorkflowEngine.OperationsView =
OCA.WorkflowEngine.TemplateView.extend({
OC.Backbone.View.extend({
templateId: '#operations-template',
collection: null,
$el: null,
events: {
'click .button-add-operation': 'add'
},
template: function(vars) {
return OCA.WorkflowEngine.Templates['operations'](_.extend(
{
addRuleGroupTXT: t('workflowengine', 'Add rule group')
},
vars
));
},
initialize: function(classname) {
if (!OCA.WorkflowEngine.availablePlugins.length) {
OCA.WorkflowEngine.availablePlugins = OC.Plugins.getPlugins('OCA.WorkflowEngine.CheckPlugins');

View File

@ -0,0 +1,109 @@
(function() {
var template = Handlebars.template, templates = OCA.WorkflowEngine.Templates = OCA.WorkflowEngine.Templates || {};
templates['operation'] = template({"1":function(container,depth0,helpers,partials,data) {
return " modified";
},"3":function(container,depth0,helpers,partials,data) {
return " <span class=\"button-delete icon-delete\"></span>\n";
},"5":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
return " <div class=\"check\" data-id=\""
+ alias4(((helper = (helper = helpers.index || (data && data.index)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"index","hash":{},"data":data}) : helper)))
+ "\">\n <select class=\"check-class\">\n"
+ ((stack1 = helpers.each.call(alias1,(depths[1] != null ? depths[1].classes : depths[1]),{"name":"each","hash":{},"fn":container.program(6, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </select>\n <select class=\"check-operator\">\n"
+ ((stack1 = helpers.each.call(alias1,(helpers.getOperators || (depth0 && depth0.getOperators) || alias2).call(alias1,(depth0 != null ? depth0["class"] : depth0),{"name":"getOperators","hash":{},"data":data}),{"name":"each","hash":{},"fn":container.program(8, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </select>\n <input type=\"text\" class=\"check-value\" value=\""
+ alias4(((helper = (helper = helpers.value || (depth0 != null ? depth0.value : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"value","hash":{},"data":data}) : helper)))
+ "\">\n <span class=\"button-delete-check icon-delete\"></span>\n </div>\n";
},"6":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
return " <option value=\""
+ alias4(((helper = (helper = helpers["class"] || (depth0 != null ? depth0["class"] : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"class","hash":{},"data":data}) : helper)))
+ "\" "
+ ((stack1 = (helpers.selectItem || (depth0 && depth0.selectItem) || alias2).call(alias1,(depth0 != null ? depth0["class"] : depth0),(depths[1] != null ? depths[1]["class"] : depths[1]),{"name":"selectItem","hash":{},"data":data})) != null ? stack1 : "")
+ ">"
+ alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
+ "</option>\n";
},"8":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
return " <option value=\""
+ alias4(((helper = (helper = helpers.operator || (depth0 != null ? depth0.operator : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"operator","hash":{},"data":data}) : helper)))
+ "\" "
+ ((stack1 = (helpers.selectItem || (depth0 && depth0.selectItem) || alias2).call(alias1,(depth0 != null ? depth0.operator : depth0),(depths[1] != null ? depths[1].operator : depths[1]),{"name":"selectItem","hash":{},"data":data})) != null ? stack1 : "")
+ ">"
+ alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
+ "</option>\n";
},"10":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {});
return ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.operation : depth0)) != null ? stack1.id : stack1),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " <button class=\"button-save pull-right\">"
+ container.escapeExpression(((helper = (helper = helpers.saveTXT || (depth0 != null ? depth0.saveTXT : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"saveTXT","hash":{},"data":data}) : helper)))
+ "</button>\n";
},"11":function(container,depth0,helpers,partials,data) {
var helper;
return " <button class=\"button-reset pull-right\">"
+ container.escapeExpression(((helper = (helper = helpers.resetTXT || (depth0 != null ? depth0.resetTXT : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"resetTXT","hash":{},"data":data}) : helper)))
+ "</button>\n";
},"13":function(container,depth0,helpers,partials,data) {
var helper;
return " <span class=\"icon-loading-small pull-right\"></span>\n <span class=\"pull-right\">"
+ container.escapeExpression(((helper = (helper = helpers.savingTXT || (depth0 != null ? depth0.savingTXT : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"savingTXT","hash":{},"data":data}) : helper)))
+ "</span>\n ";
},"15":function(container,depth0,helpers,partials,data) {
var stack1;
return ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.message : depth0),{"name":"if","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
},"16":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {});
return "\n <span class=\"msg pull-right "
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.errorMessage : depth0),{"name":"if","hash":{},"fn":container.program(17, data, 0),"inverse":container.program(19, data, 0),"data":data})) != null ? stack1 : "")
+ "\">\n "
+ container.escapeExpression(((helper = (helper = helpers.message || (depth0 != null ? depth0.message : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"message","hash":{},"data":data}) : helper)))
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.errorMessage : depth0),{"name":"if","hash":{},"fn":container.program(21, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n </span>\n ";
},"17":function(container,depth0,helpers,partials,data) {
return "error";
},"19":function(container,depth0,helpers,partials,data) {
return "success";
},"21":function(container,depth0,helpers,partials,data) {
var helper;
return " "
+ container.escapeExpression(((helper = (helper = helpers.errorMessage || (depth0 != null ? depth0.errorMessage : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"errorMessage","hash":{},"data":data}) : helper)));
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1, helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression, alias5=container.lambda;
return "<div class=\"operation"
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasChanged : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\">\n <div class=\"operation-header\">\n <input type=\"text\" class=\"operation-name\" placeholder=\""
+ alias4(((helper = (helper = helpers.shortRuleDescTXT || (depth0 != null ? depth0.shortRuleDescTXT : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"shortRuleDescTXT","hash":{},"data":data}) : helper)))
+ "\" value=\""
+ alias4(alias5(((stack1 = (depth0 != null ? depth0.operation : depth0)) != null ? stack1.name : stack1), depth0))
+ "\" />\n <input type=\"text\" class=\"operation-operation\" value=\""
+ alias4(alias5(((stack1 = (depth0 != null ? depth0.operation : depth0)) != null ? stack1.operation : stack1), depth0))
+ "\" />\n"
+ ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.operation : depth0)) != null ? stack1.id : stack1),{"name":"if","hash":{},"fn":container.program(3, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </div>\n\n <div class=\"checks\">\n"
+ ((stack1 = helpers.each.call(alias1,((stack1 = (depth0 != null ? depth0.operation : depth0)) != null ? stack1.checks : stack1),{"name":"each","hash":{},"fn":container.program(5, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ " </div>\n <button class=\"button-add\">"
+ alias4(((helper = (helper = helpers.addRuleTXT || (depth0 != null ? depth0.addRuleTXT : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"addRuleTXT","hash":{},"data":data}) : helper)))
+ "</button>\n"
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasChanged : depth0),{"name":"if","hash":{},"fn":container.program(10, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.saving : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0, blockParams, depths),"inverse":container.program(15, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "")
+ "\n</div>\n";
},"useData":true,"useDepths":true});
templates['operations'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var helper;
return "<div class=\"operations\"></div>\n<button class=\"button-add-operation\">"
+ container.escapeExpression(((helper = (helper = helpers.addRuleGroupTXT || (depth0 != null ? depth0.addRuleGroupTXT : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"addRuleGroupTXT","hash":{},"data":data}) : helper)))
+ "</button>\n";
},"useData":true});
})();

View File

@ -0,0 +1,45 @@
<div class="operation{{#if hasChanged}} modified{{/if}}">
<div class="operation-header">
<input type="text" class="operation-name" placeholder="{{shortRuleDescTXT}}" value="{{operation.name}}" />
<input type="text" class="operation-operation" value="{{operation.operation}}" />
{{! delete only makes sense if the operation is already saved }}
{{#if operation.id}}
<span class="button-delete icon-delete"></span>
{{/if}}
</div>
<div class="checks">
{{#each operation.checks}}
<div class="check" data-id="{{@index}}">
<select class="check-class">
{{#each ../classes}}
<option value="{{class}}" {{{selectItem class ../class}}}>{{name}}</option>
{{/each}}
</select>
<select class="check-operator">
{{#each (getOperators class)}}
<option value="{{operator}}" {{{selectItem operator ../operator}}}>{{name}}</option>
{{/each}}
</select>
<input type="text" class="check-value" value="{{value}}">
<span class="button-delete-check icon-delete"></span>
</div>
{{/each}}
</div>
<button class="button-add">{{addRuleTXT}}</button>
{{#if hasChanged}}
{{! reset only makes sense if the operation is already saved }}
{{#if operation.id}}
<button class="button-reset pull-right">{{resetTXT}}</button>
{{/if}}
<button class="button-save pull-right">{{saveTXT}}</button>
{{/if}}
{{#if saving}}
<span class="icon-loading-small pull-right"></span>
<span class="pull-right">{{savingTXT}}</span>
{{else}}{{#if message}}
<span class="msg pull-right {{#if errorMessage}}error{{else}}success{{/if}}">
{{message}}{{#if errorMessage}} {{errorMessage}}{{/if}}
</span>
{{/if}}{{/if}}
</div>

View File

@ -0,0 +1,2 @@
<div class="operations"></div>
<button class="button-add-operation">{{addRuleGroupTXT}}</button>

View File

@ -64,6 +64,7 @@ class Application extends \OCP\AppFramework\App {
script('workflowengine', [
'admin',
'templates',
// Check plugins
'filemimetypeplugin',

View File

@ -39,58 +39,5 @@
<p><?php p($_['description']); ?></p>
<?php endif; ?>
<script type="text/template" id="operations-template">
<div class="operations"></div>
<button class="button-add-operation"><?php p($l->t('Add rule group')); ?></button>
</script>
<script type="text/template" id="operation-template">
<div class="operation{{#if hasChanged}} modified{{/if}}">
<div class="operation-header">
<input type="text" class="operation-name" placeholder="<?php p($l->t('Short rule description')); ?>" value="{{operation.name}}" />
<input type="text" class="operation-operation" value="{{operation.operation}}" />
{{! delete only makes sense if the operation is already saved }}
{{#if operation.id}}
<span class="button-delete icon-delete"></span>
{{/if}}
</div>
<div class="checks">
{{#each operation.checks}}
<div class="check" data-id="{{@index}}">
<select class="check-class">
{{#each ../classes}}
<option value="{{class}}" {{{selectItem class ../class}}}>{{name}}</option>
{{/each}}
</select>
<select class="check-operator">
{{#each (getOperators class)}}
<option value="{{operator}}" {{{selectItem operator ../operator}}}>{{name}}</option>
{{/each}}
</select>
<input type="text" class="check-value" value="{{value}}">
<span class="button-delete-check icon-delete"></span>
</div>
{{/each}}
</div>
<button class="button-add"><?php p($l->t('Add rule')); ?></button>
{{#if hasChanged}}
{{! reset only makes sense if the operation is already saved }}
{{#if operation.id}}
<button class="button-reset pull-right"><?php p($l->t('Reset')); ?></button>
{{/if}}
<button class="button-save pull-right"><?php p($l->t('Save')); ?></button>
{{/if}}
{{#if saving}}
<span class="icon-loading-small pull-right"></span>
<span class="pull-right"><?php p($l->t('Saving…')); ?></span>
{{else}}{{#if message}}
<span class="msg pull-right {{#if errorMessage}}error{{else}}success{{/if}}">
{{message}}{{#if errorMessage}} {{errorMessage}}{{/if}}
</span>
{{/if}}{{/if}}
</div>
</script>
<div class="rules"><span class="icon-loading-small"></span> <?php p($l->t('Loading…')); ?></div>
</div>

View File

@ -25,6 +25,8 @@ handlebars -n OCA.Comments.Templates apps/comments/js/templates -f apps/comments
# Versions app
handlebars -n OCA.Versions.Templates apps/files_versions/js/templates -f apps/files_versions/js/templates.js
# Workflowengine
handlebars -n OCA.WorkflowEngine.Templates apps/workflowengine/js/templates -f apps/workflowengine/js/templates.js
if [[ $(git diff --name-only) ]]; then
echo "Please submit your compiled handlebars templates"