jsreport-scheduling
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -0,0 +0,0 @@ module.exports = { |
@@ -92,3 +92,4 @@ const parseCron = require('./parseCron') | ||
}, | ||
{ $set: { nextRun: new Date(nextRun.getTime()) } } | ||
{ $set: { nextRun: new Date(nextRun.getTime()) } }, | ||
localReqWithoutModificationDateUpdate(this.Request, this.Request({})) | ||
) | ||
@@ -186,3 +187,3 @@ | ||
{ $set: { state: 'planning' } }, | ||
req | ||
localReqWithoutModificationDateUpdate(this.Request, req) | ||
) | ||
@@ -236,3 +237,3 @@ | ||
}, | ||
req | ||
localReqWithoutModificationDateUpdate(this.Request, req) | ||
) | ||
@@ -305,1 +306,14 @@ } | ||
} | ||
function localReqWithoutModificationDateUpdate (Request, req) { | ||
if (req == null) { | ||
return req | ||
} | ||
// we create copy here to avoid persisting the context.skipModificationDateUpdate field in the | ||
// original req | ||
const localReq = Request(req) | ||
localReq.context.skipModificationDateUpdate = true | ||
return localReq | ||
} |
@@ -35,8 +35,14 @@ /*! | ||
this.reporter.documentStore.registerEntitySet('schedules', { | ||
entityType: 'jsreport.ScheduleType' | ||
entityType: 'jsreport.ScheduleType', | ||
shared: true | ||
}) | ||
this.reporter.documentStore.model.entityTypes['ReportType'].taskId = {type: 'Edm.String'} | ||
this.reporter.documentStore.registerEntitySet('tasks', {entityType: 'jsreport.TaskType'}) | ||
this.reporter.documentStore.model.entityTypes['ReportType'].taskId = { type: 'Edm.String' } | ||
this.reporter.documentStore.registerEntitySet('tasks', { | ||
entityType: 'jsreport.TaskType', | ||
shared: true, | ||
exportable: false | ||
}) | ||
reporter.initializeListeners.add(definition.name, this, () => this._initialize()) | ||
@@ -132,6 +138,32 @@ | ||
async _beforeUpdateHandler (query, update, opts, req) { | ||
const entity = update.$set | ||
const entity = update.$set || {} | ||
// only update for updates from ui | ||
if (entity.name && entity.state) { | ||
// like if it comes from studio | ||
const isFullUpdate = ( | ||
entity.hasOwnProperty('name') && | ||
entity.hasOwnProperty('cron') && | ||
entity.hasOwnProperty('state') && | ||
entity.hasOwnProperty('enabled') && | ||
entity.hasOwnProperty('templateShortid') | ||
) | ||
let schedsCache | ||
const getMatchedScheds = async () => { | ||
if (schedsCache) { | ||
return schedsCache | ||
} | ||
schedsCache = await this.reporter.documentStore.collection('schedules').find(query, req) | ||
return schedsCache | ||
} | ||
if (isFullUpdate) { | ||
if (!entity.cron) { | ||
throw this.reporter.createError('cron expression must be set', { | ||
statusCode: 400 | ||
}) | ||
} | ||
this._updateNextRun(entity) | ||
@@ -145,3 +177,5 @@ entity.state = 'planned' | ||
} | ||
} | ||
if (!isFullUpdate && entity.hasOwnProperty('cron')) { | ||
if (!entity.cron) { | ||
@@ -152,8 +186,29 @@ throw this.reporter.createError('cron expression must be set', { | ||
} | ||
this._updateNextRun(entity) | ||
entity.state = entity.state || 'planned' | ||
} | ||
if (!isFullUpdate && entity.hasOwnProperty('templateShortid')) { | ||
const scheds = await getMatchedScheds() | ||
scheds.forEach((sched) => { | ||
if (sched.enabled !== true || entity.enabled === false) { | ||
// don't do nothing if the schedule is not enabled, we only validate templateShortid for | ||
// enabled schedules | ||
return | ||
} | ||
if (!entity.templateShortid) { | ||
throw this.reporter.createError('Enabled schedules needs to include template', { | ||
statusCode: 400 | ||
}) | ||
} | ||
}) | ||
} | ||
if (entity.enabled === true) { | ||
// update next run if schedule is enabled, | ||
// this prevents generating a lot of tasks when the schedule was disabled and re-enabled after for some time | ||
const scheds = await this.reporter.documentStore.collection('schedules').find(query, req) | ||
const scheds = await getMatchedScheds() | ||
@@ -175,3 +230,3 @@ scheds.forEach((sched) => { | ||
// this allows the schedule to start clean again with no previous/pending tasks | ||
const scheds = await this.reporter.documentStore.collection('schedules').find(query, req) | ||
const scheds = await getMatchedScheds() | ||
@@ -193,2 +248,36 @@ await Promise.all(scheds.map(async (sched) => { | ||
_initialize () { | ||
if (this.definition.options.autoStart !== false) { | ||
this.start() | ||
} | ||
if (this.reporter.authorization) { | ||
const collections = [this.reporter.documentStore.collection('schedules'), this.reporter.documentStore.collection('tasks')] | ||
collections.forEach((col) => { | ||
col.beforeFindListeners.add(this.definition.name, (q, p, req) => { | ||
if (req && req.context && req.context.user && !req.context.user.isAdmin) { | ||
throw this.reporter.authorization.createAuthorizationError(col.name) | ||
} | ||
}) | ||
col.beforeInsertListeners.add(this.definition.name, (doc, req) => { | ||
if (req && req.context && req.context.user && !req.context.user.isAdmin) { | ||
throw this.reporter.authorization.createAuthorizationError(col.name) | ||
} | ||
}) | ||
col.beforeUpdateListeners.add(this.definition.name, (q, u, options, req) => { | ||
if (req && req.context && req.context.user && !req.context.user.isAdmin) { | ||
throw this.reporter.authorization.createAuthorizationError(col.name) | ||
} | ||
}) | ||
col.beforeRemoveListeners.add(this.definition.name, (q, req) => { | ||
if (req && req.context && req.context.user && !req.context.user.isAdmin) { | ||
throw this.reporter.authorization.createAuthorizationError(col.name) | ||
} | ||
}) | ||
}) | ||
} | ||
this.schedulesCollection = this.reporter.documentStore.collection('schedules') | ||
@@ -245,9 +334,3 @@ this.schedulesCollection.beforeInsertListeners.add('schedule', this._beforeCreateHandler.bind(this)) | ||
if (definition.options.autoStart !== false) { | ||
reporter.initializeListeners.add('scheduling', () => { | ||
reporter.scheduling.start() | ||
}) | ||
} | ||
reporter.closeListeners.add('scheduling', () => reporter.scheduling.stop()) | ||
} |
{ | ||
"name": "jsreport-scheduling", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "jsreport extension for scheduling background rendering jobs", | ||
@@ -45,9 +45,9 @@ "scripts": { | ||
"eslint-plugin-babel": "5.3.0", | ||
"in-publish": "2.0.0", | ||
"jsreport-authentication": "2.4.0", | ||
"jsreport-authorization": "2.2.6", | ||
"jsreport-core": "2.7.0", | ||
"jsreport-reports": "2.2.1", | ||
"in-publish": "2.0.1", | ||
"jsreport-authentication": "2.4.2", | ||
"jsreport-authorization": "2.3.0", | ||
"jsreport-core": "2.8.1", | ||
"jsreport-reports": "2.3.0", | ||
"jsreport-studio-dev": "1.5.0", | ||
"jsreport-templates": "2.3.2", | ||
"jsreport-templates": "2.3.3", | ||
"lodash": "4.17.15", | ||
@@ -54,0 +54,0 @@ "mocha": "5.2.0", |
@@ -0,0 +0,0 @@ # jsreport-scheduling |
@@ -0,0 +0,0 @@ import React, { Component } from 'react' |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ |
@@ -17,2 +17,3 @@ import ScheduleEditor from './ScheduleEditor.js' | ||
}) | ||
Studio.addEditorComponent('schedules', ScheduleEditor) | ||
@@ -19,0 +20,0 @@ Studio.addPropertiesComponent(ScheduleProperties.title, ScheduleProperties, (entity) => entity.__entitySet === 'schedules') |
@@ -51,5 +51,9 @@ import React, { Component } from 'react' | ||
if (report.contentType === 'text/html' || report.contentType === 'text/plain' || | ||
report.contentType === 'application/pdf' || (report.contentType && report.contentType.indexOf('image') !== -1)) { | ||
Studio.setPreviewFrameSrc(`/reports/${report._id}/content`) | ||
if ( | ||
report.contentType === 'text/html' || | ||
report.contentType === 'text/plain' || | ||
report.contentType === 'application/pdf' || | ||
(report.contentType && report.contentType.indexOf('image') !== -1) | ||
) { | ||
Studio.setPreviewFrameSrc(`${Studio.rootUrl}/reports/${report._id}/content`) | ||
} else { | ||
@@ -56,0 +60,0 @@ window.open(`${Studio.rootUrl}/reports/${report._id}/attachment`, '_self') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
286272
3948