From f7eece4e53666c8d5367c536c664c68d93b92e13 Mon Sep 17 00:00:00 2001 From: "honza.pofider@seznam.cz" Date: Fri, 24 Jun 2016 19:43:40 +0200 Subject: [PATCH] migrate to jsreport 1.0 --- .babelrc | 6 +- .gitignore | 5 +- package.json | 19 ++-- public/js/electron.template.model.js | 105 ------------------ public/js/electron.template.view.js | 20 ---- public/js/main_dev.js | 35 ------ public/js/main_embed_dev.js | 42 ------- public/templates/electron-template.html | 62 ----------- public/templates/embed-electron-template.html | 61 ---------- {public/js => studio}/.npmignore | 0 studio/Properties.js | 72 ++++++++++++ studio/main_dev.js | 19 ++++ 12 files changed, 110 insertions(+), 336 deletions(-) delete mode 100644 public/js/electron.template.model.js delete mode 100644 public/js/electron.template.view.js delete mode 100644 public/js/main_dev.js delete mode 100644 public/js/main_embed_dev.js delete mode 100644 public/templates/electron-template.html delete mode 100644 public/templates/embed-electron-template.html rename {public/js => studio}/.npmignore (100%) create mode 100644 studio/Properties.js create mode 100644 studio/main_dev.js diff --git a/.babelrc b/.babelrc index 15d27ad..c562d89 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,6 @@ { - "stage": 0, - "loose": "all" + "presets": ["es2015", "stage-0"], + "plugins": [ + "add-module-exports" + ] } diff --git a/.gitignore b/.gitignore index 0e85b50..7da378a 100755 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,7 @@ bower_components # compiled es5 code lib -public/js/main.js +studio/main.js +studio/main.js.map + +.idea diff --git a/package.json b/package.json index b33ea92..8215b65 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,12 @@ "scripts": { "clean": "rimraf lib", "build": "babel src --out-dir lib", - "optimize": "node node_modules/jsreport-express/tools/optimize.js", + "build-studio": "jsreport-studio-build", "lint": "eslint src test", "install-electron-prebuilt": "npm install electron-prebuilt@0.35.x", "pretest": "npm-run-all build", - "test": "mocha test/test.js --timeout 7000", - "prepublish": "npm-run-all lint clean optimize build" + "test": "mocha test/test.js --timeout 7000 --compilers js:babel-register", + "prepublish": "in-publish && jsreport-studio-build || not-in-publish && npm-run-all lint clean build" }, "author": { "name": "BJR Matos", @@ -31,21 +31,24 @@ "dependencies": { "bluebird": "3.4.0", "electron-html-to": "2.1.1", + "in-publish": "2.0.0", "lodash.pick": "4.2.1", "stream-to-array": "2.3.0" }, "devDependencies": { - "babel": "5.8.34", + "babel-cli": "6.10.1", + "babel-plugin-add-module-exports": "0.2.1", + "babel-preset-es2015": "6.9.0", + "babel-preset-stage-0": "6.5.0", + "babel-register": "6.9.0", "electron-prebuilt": "1.2.1", "eslint": "2.11.1", "eslint-config-airbnb-base": "3.0.1", "eslint-plugin-import": "1.8.1", - "jsreport-core": "0.6.4", - "jsreport-express": "0.3.2", - "jsreport-templates": "0.3.0", + "jsreport-core": "1.0.5", + "jsreport-studio-dev": "1.0.0", "mocha": "2.5.3", "npm-run-all": "2.1.1", - "requirejs": "2.2.0", "rimraf": "2.5.2", "should": "9.0.0" } diff --git a/public/js/electron.template.model.js b/public/js/electron.template.model.js deleted file mode 100644 index 390790d..0000000 --- a/public/js/electron.template.model.js +++ /dev/null @@ -1,105 +0,0 @@ -/* global define */ -/* eslint-disable no-unused-vars, no-var */ - -define(['app', 'core/basicModel', 'underscore'], function(app, ModelBase, _) { - function numberOrUndefined(param) { - if (!isNaN(param)) { - return Number(param); - } - - return undefined; - } - - function parseBoolean(param, defaultValue) { - if (param === true || param === 'true') { - return true; - } else if (param === false || param === 'false') { - return false; - } - - return defaultValue; - } - - return ModelBase.extend({ - setTemplate: function(templateModel) { - this.templateModel = templateModel; - - if (templateModel.get('electron')) { - if (templateModel.get('electron').isModel) { - this.set(templateModel.get('electron').toJSON()); - } else { - this.set(templateModel.get('electron')); - } - } - - templateModel.set('electron', this, { silent: true }); - - if (this.get('marginsType') == null) { - this.set('marginsType', 0); - this.set('marginsTypeText', 'Default'); - } - - if (this.get('landscape') == null) { - this.set('landscape', false); - this.set('orientationText', 'portrait'); - } - - if (this.get('format') == null) { - this.set('format', 'A4'); - } - - if (this.get('printBackground') == null) { - this.set('printBackground', true); - } - - this.listenTo(this, 'change', function() { - templateModel.trigger('change'); - }); - - this.listenTo(templateModel, 'api-overrides', this.apiOverride); - }, - - isDirty: function() { - return String(this.get('marginsType')) !== '0' || this.get('width') != null || this.get('height') != null || - String(this.get('printBackground')) !== 'true' || String(this.get('landscape')) !== 'false' || this.get('format') !== 'A4' || - this.get('waitForJS') != null || this.get('printDelay') != null || this.get('blockJavaScript'); - }, - - apiOverride: function(req) { - var electronApi = {}; - - if (numberOrUndefined(this.get('marginsType')) !== undefined) { - electronApi.marginsType = numberOrUndefined(this.get('marginsType')); - } - - if (this.get('format') != null) { - electronApi.format = this.get('format'); - } - - electronApi.landscape = parseBoolean(this.get('landscape'), false); - electronApi.printBackground = parseBoolean(this.get('printBackground'), true); - - if (numberOrUndefined(this.get('width')) !== undefined) { - electronApi.width = numberOrUndefined(this.get('width')); - } - - if (numberOrUndefined(this.get('height')) !== undefined) { - electronApi.height = numberOrUndefined(this.get('height')); - } - - if (numberOrUndefined(this.get('printDelay')) !== undefined) { - electronApi.printDelay = numberOrUndefined(this.get('printDelay')); - } - - if (this.get('waitForJS') != null) { - electronApi.waitForJS = parseBoolean(this.get('waitForJS'), false); - } - - if (this.get('blockJavaScript') != null) { - electronApi.blockJavaScript = parseBoolean(this.get('blockJavaScript'), false); - } - - req.template.electron = electronApi; - } - }); -}); diff --git a/public/js/electron.template.view.js b/public/js/electron.template.view.js deleted file mode 100644 index a512b15..0000000 --- a/public/js/electron.template.view.js +++ /dev/null @@ -1,20 +0,0 @@ -/* global define */ - -define(['app', 'underscore', 'marionette', 'core/view.base'], function(app, _, Marionette, ViewBase) { - return ViewBase.extend({ - tagName: 'li', - template: 'electron-template', - - initialize: function() { - _.bindAll(this, 'isFilled'); - }, - - isFilled: function() { - return this.model.isDirty(); - }, - - onClose: function() { - this.model.templateModel.unbind('api-overrides', this.model.apiOverride, this.model); - } - }); -}); diff --git a/public/js/main_dev.js b/public/js/main_dev.js deleted file mode 100644 index 0fc59cc..0000000 --- a/public/js/main_dev.js +++ /dev/null @@ -1,35 +0,0 @@ -/* global define */ -/* eslint-disable no-unused-vars, no-var */ - -define(['jquery', 'app', 'marionette', 'backbone', './electron.template.view', './electron.template.model'], -function($, app, Marionette, Backbone, TemplateView, Model) { - app.on('template-extensions-render', function(contextObj) { - var view; - - function renderRecipeMenu() { - var model; - - if (contextObj.template.get('recipe') === 'electron-pdf') { - model = new Model(); - model.setTemplate(contextObj.template); - view = new TemplateView({ model: model }); - - //wait until phantom-pdf or potentially other view unbinds from extensions menu - //otherwise binding electron.width won't apply because phantom.width is still taking place - setTimeout(function() { - contextObj.extensionsRegion.show(view, 'electron'); - }, 0); - } else { - if (view != null) { - $(view.el).remove(); - } - } - } - - renderRecipeMenu(); - - contextObj.template.on('change:recipe', function() { - renderRecipeMenu(); - }); - }); -}); diff --git a/public/js/main_embed_dev.js b/public/js/main_embed_dev.js deleted file mode 100644 index 942ea45..0000000 --- a/public/js/main_embed_dev.js +++ /dev/null @@ -1,42 +0,0 @@ -/* global define */ -/* eslint-disable no-unused-vars, no-var */ - -define(['jquery', 'app', 'marionette', 'backbone', 'core/view.base', './electron.template.model'], -function($, app, Marionette, Backbone, ViewBase, Model) { - var TemplateView = ViewBase.extend({ - template: 'embed-electron-template', - - initialize: function() { - } - }); - - app.on('extensions-menu-render', function(contextObj) { - contextObj.result += '
  • '; - - contextObj.on('after-render', function($el) { - if (contextObj.template.get('recipe') === 'electron-pdf') { - $('#electronMenuCommand').show(); - } else { - $('#electronMenuCommand').hide(); - } - - $('#electronMenuCommand').click(function() { - var model = new Model(), - view; - - model.setTemplate(contextObj.template); - - view = new TemplateView({ model: model }); - contextObj.region.show(view, 'electron'); - }); - }); - - contextObj.template.on('change:recipe', function() { - if (contextObj.template.get('recipe') === 'electron-pdf') { - $('#electronMenuCommand').show(); - } else { - $('#electronMenuCommand').hide(); - } - }); - }); -}); diff --git a/public/templates/electron-template.html b/public/templates/electron-template.html deleted file mode 100644 index f9d0199..0000000 --- a/public/templates/electron-template.html +++ /dev/null @@ -1,62 +0,0 @@ - -Electron PDF - - diff --git a/public/templates/embed-electron-template.html b/public/templates/embed-electron-template.html deleted file mode 100644 index 7ffeec4..0000000 --- a/public/templates/embed-electron-template.html +++ /dev/null @@ -1,61 +0,0 @@ - -
    -
    - Margin Type - -
    - -
    - Paper Format - -
    - -
    - Web Page width - -
    - -
    - Web Page height - -
    - -
    - Orientation - - -
    -
    diff --git a/public/js/.npmignore b/studio/.npmignore similarity index 100% rename from public/js/.npmignore rename to studio/.npmignore diff --git a/studio/Properties.js b/studio/Properties.js new file mode 100644 index 0000000..980fe1d --- /dev/null +++ b/studio/Properties.js @@ -0,0 +1,72 @@ +import React, { Component } from 'react' +import Studio from 'jsreport-studio' + +export default class Properties extends Component { + render () { + const { entity, onChange } = this.props + const electron = entity.electron || {} + + const change = (change) => onChange(Object.assign({}, entity, { electron: Object.assign({}, entity.electron, change) })) + + return ( +
    +
    + +
    +
    + +
    +
    + electron({width: v.target.value})} /> +
    +
    + electron({height: v.target.value})} /> +
    +
    + +
    +
    + change({printBackground: v.target.checked})} /> +
    + +
    + change({printDelay: v.target.value})} /> +
    +
    + + change({waitForJS: v.target.checked})} /> +
    +
    + + change({blockJavaScript: v.target.checked})} /> +
    +
    + ) + } +} + diff --git a/studio/main_dev.js b/studio/main_dev.js new file mode 100644 index 0000000..5c24b38 --- /dev/null +++ b/studio/main_dev.js @@ -0,0 +1,19 @@ +import Properties from './Properties.js' +import Studio from 'jsreport-studio' + +Studio.addPropertiesComponent('electron-pdf', Properties, (entity) => entity.__entitySet === 'templates' && entity.recipe === 'electron-pdf'); + +Studio.addApiSpec({ + template: { + electron: { + landscape: true, + format: '...', + printBackground: true, + width: 100, + height: 100, + printDelay: 1000, + blockJavaScript: false, + waitForJS: true + } + } +});