angular-formio
Version:
Form.io Angular JSON Form Renderer ========================== This library serves as a Dynamic JSON Powered Form rendering library for [Angular](https://angular.io). This works by providing a JSON schema to a ```<formio>``` Angular component, where that f
1,292 lines (1,272 loc) • 243 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('formiojs'), require('lodash'), require('lodash/each'), require('lodash/intersection'), require('@angular/router'), require('rxjs'), require('ngx-bootstrap/modal'), require('@angular/common'), require('@angular/forms'), require('formiojs/utils/Evaluator'), require('ngx-bootstrap/pagination')) :
typeof define === 'function' && define.amd ? define('index', ['exports', '@angular/core', 'formiojs', 'lodash', 'lodash/each', 'lodash/intersection', '@angular/router', 'rxjs', 'ngx-bootstrap/modal', '@angular/common', '@angular/forms', 'formiojs/utils/Evaluator', 'ngx-bootstrap/pagination'], factory) :
(global = global || self, factory(global['formio-manager'] = {}, global.core, global.formiojs, global._, global._each, global._intersection, global.router, global.rxjs, global.modal, global.common, global.forms, global.Evaluator, global.pagination));
}(this, (function (exports, core, formiojs, _, _each, _intersection, router, rxjs, modal, common, forms, Evaluator, pagination) { 'use strict';
var ___default = 'default' in _ ? _['default'] : _;
_each = _each && _each.hasOwnProperty('default') ? _each['default'] : _each;
_intersection = _intersection && _intersection.hasOwnProperty('default') ? _intersection['default'] : _intersection;
Evaluator = Evaluator && Evaluator.hasOwnProperty('default') ? Evaluator['default'] : Evaluator;
/**
* @fileoverview added by tsickle
* Generated from: manager/form-manager.config.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormManagerConfig = /** @class */ (function () {
function FormManagerConfig() {
this.tag = '';
this.includeSearch = false;
this.saveDraft = false;
}
FormManagerConfig.decorators = [
{ type: core.Injectable },
];
return FormManagerConfig;
}());
/**
* @fileoverview added by tsickle
* Generated from: formio.config.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAppConfig = /** @class */ (function () {
function FormioAppConfig() {
this.appUrl = '';
this.apiUrl = '';
}
FormioAppConfig.decorators = [
{ type: core.Injectable },
];
return FormioAppConfig;
}());
/**
* @fileoverview added by tsickle
* Generated from: auth/auth.config.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAuthConfig = /** @class */ (function () {
function FormioAuthConfig() {
}
FormioAuthConfig.decorators = [
{ type: core.Injectable },
];
return FormioAuthConfig;
}());
/**
* @fileoverview added by tsickle
* Generated from: auth/auth.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAuthService = /** @class */ (function () {
function FormioAuthService(appConfig, config) {
var _this = this;
this.appConfig = appConfig;
this.config = config;
this.authenticated = false;
this.formAccess = {};
this.submissionAccess = {};
this.is = {};
this.user = null;
if (this.appConfig && this.appConfig.appUrl) {
formiojs.Formio.setBaseUrl(this.appConfig.apiUrl);
formiojs.Formio.setProjectUrl(this.appConfig.appUrl);
formiojs.Formio.formOnly = !!this.appConfig.formOnly;
}
else {
console.error('You must provide an AppConfig within your application!');
}
this.loginForm =
this.appConfig.appUrl +
'/' +
_.get(this.config, 'login.form', 'user/login');
this.registerForm =
this.appConfig.appUrl +
'/' +
_.get(this.config, 'register.form', 'user/register');
this.onLogin = new core.EventEmitter();
this.onLogout = new core.EventEmitter();
this.onRegister = new core.EventEmitter();
this.onUser = new core.EventEmitter();
this.onError = new core.EventEmitter();
this.ready = new Promise((/**
* @param {?} resolve
* @param {?} reject
* @return {?}
*/
function (resolve, reject) {
_this.readyResolve = resolve;
_this.readyReject = reject;
}));
// Register for the core events.
formiojs.Formio.events.on('formio.badToken', (/**
* @return {?}
*/
function () { return _this.logoutError(); }));
formiojs.Formio.events.on('formio.sessionExpired', (/**
* @return {?}
*/
function () { return _this.logoutError(); }));
if (!this.config.delayAuth) {
this.init();
}
}
/**
* @param {?} submission
* @return {?}
*/
FormioAuthService.prototype.onLoginSubmit = /**
* @param {?} submission
* @return {?}
*/
function (submission) {
this.setUser(submission);
this.onLogin.emit(submission);
};
/**
* @param {?} submission
* @return {?}
*/
FormioAuthService.prototype.onRegisterSubmit = /**
* @param {?} submission
* @return {?}
*/
function (submission) {
this.setUser(submission);
this.onRegister.emit(submission);
};
/**
* @return {?}
*/
FormioAuthService.prototype.init = /**
* @return {?}
*/
function () {
var _this = this;
this.projectReady = formiojs.Formio.makeStaticRequest(this.appConfig.appUrl).then((/**
* @param {?} project
* @return {?}
*/
function (project) {
_.each(project.access, (/**
* @param {?} access
* @return {?}
*/
function (access) {
_this.formAccess[access.type] = access.roles;
}));
}), (/**
* @return {?}
*/
function () {
_this.formAccess = {};
return null;
}));
// Get the access for this project.
this.accessReady = formiojs.Formio.makeStaticRequest(this.appConfig.appUrl + '/access').then((/**
* @param {?} access
* @return {?}
*/
function (access) {
_.each(access.forms, (/**
* @param {?} form
* @return {?}
*/
function (form) {
_this.submissionAccess[form.name] = {};
form.submissionAccess.forEach((/**
* @param {?} subAccess
* @return {?}
*/
function (subAccess) {
_this.submissionAccess[form.name][subAccess.type] = subAccess.roles;
}));
}));
_this.roles = access.roles;
return access;
}), (/**
* @return {?}
*/
function () {
_this.roles = {};
return null;
}));
/** @type {?} */
var currentUserPromise;
if (this.config.oauth) {
// Make a fix to the hash to remove starting "/" that angular might put there.
if (window.location.hash && window.location.hash.match(/^#\/access_token/)) {
history.pushState(null, null, window.location.hash.replace(/^#\/access_token/, '#access_token'));
}
// Initiate the SSO if they provide oauth settings.
currentUserPromise = formiojs.Formio.ssoInit(this.config.oauth.type, this.config.oauth.options);
}
else {
currentUserPromise = formiojs.Formio.currentUser();
}
this.userReady = currentUserPromise.then((/**
* @param {?} user
* @return {?}
*/
function (user) {
_this.setUser(user);
return user;
}));
// Trigger we are redy when all promises have resolved.
if (this.accessReady) {
this.accessReady
.then((/**
* @return {?}
*/
function () { return _this.projectReady; }))
.then((/**
* @return {?}
*/
function () { return _this.userReady; }))
.then((/**
* @return {?}
*/
function () { return _this.readyResolve(true); }))
.catch((/**
* @param {?} err
* @return {?}
*/
function (err) { return _this.readyReject(err); }));
}
};
/**
* @param {?} user
* @return {?}
*/
FormioAuthService.prototype.setUser = /**
* @param {?} user
* @return {?}
*/
function (user) {
/** @type {?} */
var namespace = formiojs.Formio.namespace || 'formio';
if (user) {
this.user = user;
localStorage.setItem(namespace + "AppUser", JSON.stringify(user));
this.setUserRoles();
}
else {
this.user = null;
this.is = {};
localStorage.removeItem(namespace + "AppUser");
formiojs.Formio.clearCache();
formiojs.Formio.setUser(null);
}
this.authenticated = !!formiojs.Formio.getToken();
this.onUser.emit(this.user);
};
/**
* @return {?}
*/
FormioAuthService.prototype.setUserRoles = /**
* @return {?}
*/
function () {
var _this = this;
if (this.accessReady) {
this.accessReady.then((/**
* @return {?}
*/
function () {
_.each(_this.roles, (/**
* @param {?} role
* @param {?} roleName
* @return {?}
*/
function (role, roleName) {
if (_this.user.roles.indexOf(role._id) !== -1) {
_this.is[roleName] = true;
}
}));
}));
}
};
/**
* @return {?}
*/
FormioAuthService.prototype.logoutError = /**
* @return {?}
*/
function () {
this.setUser(null);
localStorage.removeItem('formioToken');
this.onError.emit();
};
/**
* @return {?}
*/
FormioAuthService.prototype.logout = /**
* @return {?}
*/
function () {
var _this = this;
this.setUser(null);
localStorage.removeItem('formioToken');
formiojs.Formio.logout()
.then((/**
* @return {?}
*/
function () { return _this.onLogout.emit(); }))
.catch((/**
* @return {?}
*/
function () { return _this.logoutError(); }));
};
FormioAuthService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
FormioAuthService.ctorParameters = function () { return [
{ type: FormioAppConfig },
{ type: FormioAuthConfig }
]; };
return FormioAuthService;
}());
/**
* @fileoverview added by tsickle
* Generated from: manager/form-manager.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormManagerService = /** @class */ (function () {
function FormManagerService(appConfig, config, auth) {
var _this = this;
this.appConfig = appConfig;
this.config = config;
this.auth = auth;
this.form = null;
this.perms = { delete: false, edit: false };
if (this.appConfig && this.appConfig.appUrl) {
formiojs.Formio.setBaseUrl(this.appConfig.apiUrl);
formiojs.Formio.setProjectUrl(this.appConfig.appUrl);
}
else {
console.error('You must provide an AppConfig within your application!');
}
this.allAccessMap = {
'update_all': 'formEdit',
'delete_all': 'formDelete'
};
this.ownAccessMap = {
'update_own': 'formEdit',
'delete_own': 'formDelete'
};
this.actionAllowed = (/**
* @param {?} action
* @return {?}
*/
function (action) { return _this.isActionAllowed(action); });
this.reset();
}
/**
* @param {?} action
* @return {?}
*/
FormManagerService.prototype.isActionAllowed = /**
* @param {?} action
* @return {?}
*/
function (action) {
return this.access[action];
};
/**
* @return {?}
*/
FormManagerService.prototype.setAccess = /**
* @return {?}
*/
function () {
var _this = this;
this.access = {
formCreate: true,
formView: true,
formEdit: true,
formDelete: true,
submissionIndex: true
};
if (this.auth) {
this.access = {
formCreate: false,
formView: false,
formEdit: false,
formDelete: false,
submissionIndex: false
};
this.ready = this.auth.ready.then((/**
* @return {?}
*/
function () {
/** @type {?} */
var adminRoles = [];
_each(_this.auth.roles, (/**
* @param {?} role
* @param {?} name
* @return {?}
*/
function (role, name) {
if (role.admin) {
adminRoles.push(role._id);
}
}));
if (_this.auth.user && _this.auth.user.roles) {
_this.auth.user.roles.forEach((/**
* @param {?} roleId
* @return {?}
*/
function (roleId) {
if (adminRoles.indexOf(roleId) !== -1) {
_this.access.formCreate = true;
_this.access.formView = true;
_this.access.formEdit = true;
_this.access.formDelete = true;
_this.access.submissionIndex = true;
}
if (!_this.access.formCreate) {
_this.access.formCreate = (_this.auth.formAccess.create_all.indexOf(roleId) !== -1);
}
if (!_this.access.formView) {
_this.access.formView = (_this.auth.formAccess.read_all.indexOf(roleId) !== -1);
}
if (!_this.access.formEdit) {
_this.access.formEdit = (_this.auth.formAccess.update_all.indexOf(roleId) !== -1);
}
if (!_this.access.formDelete) {
_this.access.formDelete = (_this.auth.formAccess.delete_all.indexOf(roleId) !== -1);
}
if (!_this.access.submissionIndex) {
_this.access.submissionIndex = (_this.auth.formAccess.read_all.indexOf(roleId) !== -1);
}
}));
}
}));
}
else {
this.ready = Promise.resolve(false);
}
};
/**
* @param {?=} route
* @return {?}
*/
FormManagerService.prototype.reset = /**
* @param {?=} route
* @return {?}
*/
function (route) {
var _this = this;
if (route) {
route.params.subscribe((/**
* @param {?} params
* @return {?}
*/
function (params) {
if (params.id) {
_this.formio = new formiojs.Formio(_this.formio.formsUrl + "/" + params.id);
}
else {
_this.reset();
}
}));
}
else {
this.formio = new formiojs.Formio(this.appConfig.appUrl);
this.setAccess();
}
};
/**
* @param {?} roles
* @return {?}
*/
FormManagerService.prototype.hasAccess = /**
* @param {?} roles
* @return {?}
*/
function (roles) {
if (!this.auth.user) {
return false;
}
return !!_intersection(roles, this.auth.user.roles).length;
};
/**
* @param {?} form
* @return {?}
*/
FormManagerService.prototype.setForm = /**
* @param {?} form
* @return {?}
*/
function (form) {
var _this = this;
this.form = form;
if (form.access) {
// Check if they have access here.
form.access.forEach((/**
* @param {?} access
* @return {?}
*/
function (access) {
// Check for all access.
if (_this.allAccessMap[access.type] && !_this.access[_this.allAccessMap[access.type]]) {
_this.access[_this.allAccessMap[access.type]] = _this.hasAccess(access.roles);
}
// Check for own access.
if (_this.auth && _this.auth.user &&
(form._id === _this.auth.user._id) &&
_this.ownAccessMap[access.type] &&
!_this.access[_this.ownAccessMap[access.type]]) {
_this.access[_this.ownAccessMap[access.type]] = _this.hasAccess(access.roles);
}
}));
}
return form;
};
/**
* @return {?}
*/
FormManagerService.prototype.loadForm = /**
* @return {?}
*/
function () {
var _this = this;
return this.formio.loadForm().then((/**
* @param {?} form
* @return {?}
*/
function (form) { return _this.setForm(form); }));
};
/**
* @param {?} route
* @return {?}
*/
FormManagerService.prototype.setSubmission = /**
* @param {?} route
* @return {?}
*/
function (route) {
var _this = this;
return new Promise((/**
* @param {?} resolve
* @return {?}
*/
function (resolve) {
route.params.subscribe((/**
* @param {?} params
* @return {?}
*/
function (params) {
_this.formio = new formiojs.Formio(_this.formio.submissionsUrl + "/" + params.id);
resolve(_this.formio);
}));
}));
};
/**
* @param {?} submission
* @return {?}
*/
FormManagerService.prototype.submissionLoaded = /**
* @param {?} submission
* @return {?}
*/
function (submission) {
var _this = this;
this.auth.ready.then((/**
* @return {?}
*/
function () {
_this.formio.userPermissions(_this.auth.user, _this.form, submission).then((/**
* @param {?} perms
* @return {?}
*/
function (perms) {
_this.perms.delete = perms.delete;
_this.perms.edit = perms.edit;
}));
}));
};
/**
* @return {?}
*/
FormManagerService.prototype.loadForms = /**
* @return {?}
*/
function () {
return this.formio.loadForms({ params: {
tags: this.config.tag
} });
};
/**
* @param {?} form
* @return {?}
*/
FormManagerService.prototype.createForm = /**
* @param {?} form
* @return {?}
*/
function (form) {
return this.formio.createform(form);
};
FormManagerService.decorators = [
{ type: core.Injectable },
];
/** @nocollapse */
FormManagerService.ctorParameters = function () { return [
{ type: FormioAppConfig },
{ type: FormManagerConfig },
{ type: FormioAuthService }
]; };
return FormManagerService;
}());
/**
* @fileoverview added by tsickle
* Generated from: components/loader/formio.loader.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioLoader = /** @class */ (function () {
function FormioLoader() {
this.loading$ = new rxjs.BehaviorSubject(true);
this.loading = true;
}
/**
* @param {?} loading
* @return {?}
*/
FormioLoader.prototype.setLoading = /**
* @param {?} loading
* @return {?}
*/
function (loading) {
this.loading = loading;
this.loading$.next(loading);
};
FormioLoader.decorators = [
{ type: core.Injectable },
];
return FormioLoader;
}());
/**
* @fileoverview added by tsickle
* Generated from: components/alerts/formio.alerts.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioAlerts = /** @class */ (function () {
function FormioAlerts() {
this.alerts = [];
}
/**
* @param {?} alert
* @return {?}
*/
FormioAlerts.prototype.setAlert = /**
* @param {?} alert
* @return {?}
*/
function (alert) {
this.alerts = [alert];
};
/**
* @param {?} alert
* @return {?}
*/
FormioAlerts.prototype.addAlert = /**
* @param {?} alert
* @return {?}
*/
function (alert) {
this.alerts.push(alert);
};
/**
* @param {?} alerts
* @return {?}
*/
FormioAlerts.prototype.setAlerts = /**
* @param {?} alerts
* @return {?}
*/
function (alerts) {
this.alerts = alerts;
};
return FormioAlerts;
}());
/**
* @fileoverview added by tsickle
* Generated from: grid/GridHeaderComponent.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var GridHeaderComponent = /** @class */ (function () {
function GridHeaderComponent() {
this.headers = [];
this.sort = new core.EventEmitter();
}
Object.defineProperty(GridHeaderComponent.prototype, "numHeaders", {
get: /**
* @return {?}
*/
function () {
return this.headers.length;
},
enumerable: true,
configurable: true
});
/**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
GridHeaderComponent.prototype.load = /**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
function (formio, query) {
return Promise.resolve([]);
};
GridHeaderComponent.propDecorators = {
actionAllowed: [{ type: core.Input }],
sort: [{ type: core.Output }],
template: [{ type: core.ViewChild, args: [core.TemplateRef, { static: true },] }]
};
return GridHeaderComponent;
}());
var __extends = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var FormGridHeaderComponent = /** @class */ (function (_super) {
__extends(FormGridHeaderComponent, _super);
function FormGridHeaderComponent() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @param {?=} formio
* @return {?}
*/
FormGridHeaderComponent.prototype.load = /**
* @param {?=} formio
* @return {?}
*/
function (formio) {
this.header = {
label: 'Title',
key: 'title',
sort: 'asc'
};
this.headers = [this.header];
return Promise.resolve(this.headers);
};
Object.defineProperty(FormGridHeaderComponent.prototype, "numHeaders", {
get: /**
* @return {?}
*/
function () {
return 2;
},
enumerable: true,
configurable: true
});
FormGridHeaderComponent.decorators = [
{ type: core.Component, args: [{
selector: 'form-grid-header',
template: "<ng-template> <thead> <tr> <th> <div class=\"row\"> <div class=\"col-sm-8\"> <a (click)=\"sort.emit(header)\"> {{ header.label }} <span [ngClass]=\"{'glyphicon-triangle-top fa-caret-up': (header.sort === 'asc'), 'glyphicon-triangle-bottom fa-caret-down': (header.sort === 'desc')}\" class=\"glyphicon fa\" *ngIf=\"header.sort\"></span> </a> </div> <div class=\"col-sm-4\"> Operations </div> </div> </th> </tr> </thead> </ng-template> "
},] },
];
return FormGridHeaderComponent;
}(GridHeaderComponent));
/**
* @fileoverview added by tsickle
* Generated from: grid/GridBodyComponent.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var GridBodyComponent = /** @class */ (function () {
function GridBodyComponent() {
this.firstItem = 0;
this.lastItem = 0;
this.skip = 0;
this.limit = 0;
this.total = 0;
this.rowSelect = new core.EventEmitter();
this.rowAction = new core.EventEmitter();
this.loading = true;
}
/**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
GridBodyComponent.prototype.load = /**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
function (formio, query) {
return Promise.resolve({});
};
/**
* @param {?} event
* @param {?} row
* @return {?}
*/
GridBodyComponent.prototype.onRowSelect = /**
* @param {?} event
* @param {?} row
* @return {?}
*/
function (event, row) {
event.preventDefault();
this.rowSelect.emit(row);
};
/**
* @param {?} event
* @param {?} row
* @param {?} action
* @return {?}
*/
GridBodyComponent.prototype.onRowAction = /**
* @param {?} event
* @param {?} row
* @param {?} action
* @return {?}
*/
function (event, row, action) {
event.preventDefault();
this.rowAction.emit({ row: row, action: action });
};
/**
* Set the rows for this Grid body.
*
* @param query
* @param items
* @return any
*/
/**
* Set the rows for this Grid body.
*
* @param {?} query
* @param {?} items
* @return {?} any
*/
GridBodyComponent.prototype.setRows = /**
* Set the rows for this Grid body.
*
* @param {?} query
* @param {?} items
* @return {?} any
*/
function (query, items) {
var _this = this;
this.rows = [];
this.firstItem = query.skip + 1;
this.lastItem = this.firstItem + items.length - 1;
this.total = items.serverCount;
this.limit = query.limit;
this.skip = Math.floor(items.skip / query.limit) + 1;
this.loading = false;
_.each(items, (/**
* @param {?} item
* @return {?}
*/
function (item) {
_this.rows.push(_.clone(item));
}));
return this.rows;
};
GridBodyComponent.propDecorators = {
header: [{ type: core.Input }],
actionAllowed: [{ type: core.Input }],
rowSelect: [{ type: core.Output }],
rowAction: [{ type: core.Output }],
template: [{ type: core.ViewChild, args: [core.TemplateRef, { static: true },] }]
};
return GridBodyComponent;
}());
var __extends$1 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var FormGridBodyComponent = /** @class */ (function (_super) {
__extends$1(FormGridBodyComponent, _super);
function FormGridBodyComponent() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
FormGridBodyComponent.prototype.load = /**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
function (formio, query) {
var _this = this;
query = query || {};
return formio.loadForms({ params: query }).then((/**
* @param {?} forms
* @return {?}
*/
function (forms) { return _this.setRows(query, forms); }));
};
FormGridBodyComponent.decorators = [
{ type: core.Component, args: [{
selector: 'form-grid-body',
styles: [".form-btn { font-size: 0.75rem; } "],
template: "<ng-template> <tbody *ngIf=\"rows\"> <tr *ngFor=\"let form of rows\"> <td> <div class=\"row\"> <div class=\"col-sm-8\"> <a routerLink=\"{{form._id}}/view\" (click)=\"onRowSelect($event, form)\"><h5>{{ form.title }}</h5></a> </div> <div class=\"col-sm-4\"> <button *ngIf=\"actionAllowed('formView')\" class=\"btn btn-secondary btn-sm form-btn\" (click)=\"onRowAction($event, form, 'view')\"><span class=\"fa fa-pencil\"></span> Enter Data</button> <button *ngIf=\"actionAllowed('submissionIndex')\" class=\"btn btn-secondary btn-sm form-btn\" (click)=\"onRowAction($event, form, 'submission')\"><span class=\"fa fa-list-alt\"></span> View Data</button> <button *ngIf=\"actionAllowed('formEdit')\" class=\"btn btn-secondary btn-sm form-btn\" (click)=\"onRowAction($event, form, 'edit')\"><span class=\"fa fa-edit\"></span> Edit Form</button> <button *ngIf=\"actionAllowed('formDelete')\" class=\"btn btn-secondary btn-sm form-btn\" (click)=\"onRowAction($event, form, 'delete')\"><span class=\"fa fa-trash\"></span></button> </div> </div> </td> </tr> </tbody> </ng-template> "
},] },
];
return FormGridBodyComponent;
}(GridBodyComponent));
/**
* @fileoverview added by tsickle
* Generated from: grid/GridFooterComponent.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var GridFooterComponent = /** @class */ (function () {
function GridFooterComponent() {
this.pageChanged = new core.EventEmitter();
this.createItem = new core.EventEmitter();
}
GridFooterComponent.propDecorators = {
header: [{ type: core.Input }],
body: [{ type: core.Input }],
createText: [{ type: core.Input }],
size: [{ type: core.Input }],
actionAllowed: [{ type: core.Input }],
pageChanged: [{ type: core.Output }],
createItem: [{ type: core.Output }],
template: [{ type: core.ViewChild, args: [core.TemplateRef, { static: true },] }]
};
return GridFooterComponent;
}());
var __extends$2 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var FormGridFooterComponent = /** @class */ (function (_super) {
__extends$2(FormGridFooterComponent, _super);
function FormGridFooterComponent() {
return _super.call(this) || this;
}
/**
* @return {?}
*/
FormGridFooterComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
if (!this.createText) {
this.createText = 'Create Form';
}
if (!this.size) {
this.size = 7;
}
};
FormGridFooterComponent.decorators = [
{ type: core.Component, args: [{
template: "<ng-template> <tfoot class=\"formio-grid-footer\"> <tr> <td *ngIf=\"header\" [colSpan]=\"header.numHeaders\"> <button *ngIf=\"actionAllowed('formCreate')\" class=\"btn btn-primary pull-left float-left\" (click)=\"createItem.emit('form')\"><i class=\"glyphicon glyphicon-plus fa fa-plus\"></i> {{ createText }}</button> <span class=\"pull-right float-right item-counter\"><span class=\"page-num\">{{ body.firstItem }} - {{ body.lastItem }}</span> / {{ body.total }} total</span> <pagination [totalItems]=\"body.total\" [itemsPerPage]=\"body.limit\" [(ngModel)]=\"body.skip\" (pageChanged)=\"pageChanged.emit($event)\" [maxSize]=\"size\" class=\"justify-content-center pagination-sm\"> </pagination> </td> </tr> </tfoot> </ng-template> ",
styles: ["tfoot.formio-grid-footer td { padding: 0.3rem; } tfoot.formio-grid-footer .page-num { font-size: 1.4em; } tfoot.formio-grid-footer ul.pagination { margin-top: 5px; margin-bottom: 0; } "],
encapsulation: core.ViewEncapsulation.None
},] },
];
/** @nocollapse */
FormGridFooterComponent.ctorParameters = function () { return []; };
return FormGridFooterComponent;
}(GridFooterComponent));
/**
* @fileoverview added by tsickle
* Generated from: grid/form/index.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormComponents = {
header: FormGridHeaderComponent,
body: FormGridBodyComponent,
footer: FormGridFooterComponent
};
var __extends$3 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var SubmissionGridHeaderComponent = /** @class */ (function (_super) {
__extends$3(SubmissionGridHeaderComponent, _super);
function SubmissionGridHeaderComponent() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
SubmissionGridHeaderComponent.prototype.load = /**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
function (formio, query) {
var _this = this;
query = query || {};
return formio.loadForm({ params: query }).then((/**
* @param {?} form
* @return {?}
*/
function (form) {
_this.headers = [];
formiojs.Utils.eachComponent(form.components, (/**
* @param {?} component
* @return {?}
*/
function (component) {
if (component.input &&
(!component.hasOwnProperty('tableView') || component.tableView)) {
_this.headers.push({
label: component.label,
key: 'data.' + component.key,
sort: '',
component: formiojs.Components.create(component, null, null, true)
});
}
}), true);
return _this.headers;
}));
};
SubmissionGridHeaderComponent.decorators = [
{ type: core.Component, args: [{
template: "<ng-template> <thead> <tr> <th *ngFor=\"let header of headers\"> <a (click)=\"sort.emit(header)\"> {{ header.label }} <span [ngClass]=\"{'glyphicon-triangle-top': (header.sort === 'asc'), 'glyphicon-triangle-bottom': (header.sort === 'desc')}\" class=\"glyphicon\" *ngIf=\"header.sort\"></span> </a> </th> </tr> </thead> </ng-template> "
},] },
];
return SubmissionGridHeaderComponent;
}(GridHeaderComponent));
var __extends$4 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var SubmissionGridBodyComponent = /** @class */ (function (_super) {
__extends$4(SubmissionGridBodyComponent, _super);
function SubmissionGridBodyComponent() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
SubmissionGridBodyComponent.prototype.load = /**
* @param {?} formio
* @param {?=} query
* @return {?}
*/
function (formio, query) {
var _this = this;
query = query || {};
return formio.loadSubmissions({ params: query })
.then((/**
* @param {?} submissions
* @return {?}
*/
function (submissions) { return _this.setRows(query, submissions); }));
};
/**
* Render the cell data.
*
* @param row
* @param header
* @return any
*/
/**
* Render the cell data.
*
* @param {?} row
* @param {?} header
* @return {?} any
*/
SubmissionGridBodyComponent.prototype.view = /**
* Render the cell data.
*
* @param {?} row
* @param {?} header
* @return {?} any
*/
function (row, header) {
/** @type {?} */
var cellValue = _.get(row, header.key);
if (typeof header.component.getView === 'function') {
return header.component.getView(cellValue);
}
return header.component.asString(cellValue);
};
SubmissionGridBodyComponent.decorators = [
{ type: core.Component, args: [{
template: "<ng-template> <tbody> <tr *ngFor=\"let row of rows\" (click)=\"onRowSelect($event, row)\"> <td *ngFor=\"let rowHeader of header.headers\" [innerHTML]=\"view(row, rowHeader)\"></td> </tr> </tbody> </ng-template> "
},] },
];
return SubmissionGridBodyComponent;
}(GridBodyComponent));
var __extends$5 = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var SubmissionGridFooterComponent = /** @class */ (function (_super) {
__extends$5(SubmissionGridFooterComponent, _super);
function SubmissionGridFooterComponent() {
return _super.call(this) || this;
}
/**
* @return {?}
*/
SubmissionGridFooterComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
if (!this.size) {
this.size = 7;
}
};
SubmissionGridFooterComponent.decorators = [
{ type: core.Component, args: [{
template: "<ng-template> <tfoot class=\"formio-grid-footer\"> <tr> <td *ngIf=\"header\" [colSpan]=\"header.numHeaders\"> <button *ngIf=\"actionAllowed('submissionCreate') && createText\" class=\"btn btn-primary pull-left float-left\" (click)=\"createItem.emit('form')\"><i class=\"glyphicon glyphicon-plus fa fa-plus\"></i> {{ createText }}</button> <span class=\"pull-right float-right item-counter\"><span class=\"page-num\">{{ body.firstItem }} - {{ body.lastItem }}</span> / {{ body.total }} total</span> <pagination [totalItems]=\"body.total\" [itemsPerPage]=\"body.limit\" [(ngModel)]=\"body.skip\" (pageChanged)=\"pageChanged.emit($event)\" [maxSize]=\"size\" class=\"justify-content-center pagination-sm\"></pagination> </td> </tr> </tfoot> </ng-template> ",
styles: ["tfoot.formio-grid-footer td { padding: 0.3rem; } tfoot.formio-grid-footer .page-num { font-size: 1.4em; } tfoot.formio-grid-footer ul.pagination { margin-top: 5px; margin-bottom: 0; } "],
encapsulation: core.ViewEncapsulation.None
},] },
];
/** @nocollapse */
SubmissionGridFooterComponent.ctorParameters = function () { return []; };
return SubmissionGridFooterComponent;
}(GridFooterComponent));
/**
* @fileoverview added by tsickle
* Generated from: grid/submission/index.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var SubmissionComponents = {
header: SubmissionGridHeaderComponent,
body: SubmissionGridBodyComponent,
footer: SubmissionGridFooterComponent
};
/**
* @fileoverview added by tsickle
* Generated from: grid/grid.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FormioGridComponent = /** @class */ (function () {
function FormioGridComponent(loader, alerts, resolver, ref) {
this.loader = loader;
this.alerts = alerts;
this.resolver = resolver;
this.ref = ref;
this.page = 0;
this.isLoading = false;
this.initialized = false;
this.select = this.rowSelect = new core.EventEmitter();
this.rowAction = new core.EventEmitter();
this.createItem = new core.EventEmitter();
this.error = new core.EventEmitter();
this.loader.setLoading(true);
}
/**
* @param {?} property
* @param {?} component
* @return {?}
*/
FormioGridComponent.prototype.createComponent = /**
* @param {?} property
* @param {?} component
* @return {?}
*/
function (property, component) {
/** @type {?} */
var factory = this.resolver.resolveComponentFactory(component);
/** @type {?} */
var componentRef = property.createComponent(factory);
return componentRef.instance;
};
/**
* @param {?=} src
* @return {?}
*/
FormioGridComponent.prototype.loadGrid = /**
* @param {?=} src
* @return {?}
*/
function (src) {
var _this = this;
// If no source is provided, then skip.
if (!src && !this.formio) {
return;
}
// Do not double load.
if (this.formio && this.src && (src === this.src)) {
return;
}
if (src) {
this.src = src;
this.formio = new formiojs.Formio(this.src, { formOnly: true });
}
// Load the header.
this.header.load(this.formio)
.then((/**
* @return {?}
*/
function () { return _this.setPage(0); }))
.catch((/**
* @param {?} error
* @return {?}
*/
function (error) { return _this.onError(error); }));
};
/**
* @return {?}
*