Skip to content

Instantly share code, notes, and snippets.

View travist's full-sized avatar

Travis Tidwell travist

View GitHub Profile
@travist
travist / mongo.js
Last active March 29, 2022 13:52
Delete a Project within MongoDB, and all MongoDB documents within that Project
db.projects.find({_id:ObjectId('5c77ef689ea802484df52353')}).forEach(function(project) {
print('Deleting the following project and all resources.');
printjson(project);
db.forms.find({project: project._id}).forEach(function(form) {
print('Deleting form ' + form._id);
print('Deleting form(' + form._id + ') submissions');
db.submissions.deleteMany({form: form._id});
print('Deleting form(' + form._id + ') actions');
db.actions.deleteMany({form: form._id});
print('Deleting form(' + form._id + ') revisions');
@travist
travist / renderer.ts
Created June 14, 2018 02:21
Access Core renderer within Angular renderer
import { Component, AfterViewInit, ViewChild } from '@angular/core';
import { FormioComponent } from 'angular-formio';
@Component({
template: '<formio src="https://examples.form.io/example"></formio>'
})
export class FormRenderComponent implements AfterViewInit {
@ViewChild(FormioComponent) formioComponent: FormioComponent;
ngAfterViewInit() {
this.formioComponent.ready.then((formio) => {
@travist
travist / select.js
Created June 5, 2018 14:47
Override a Form.io component
// This shows how to override a Form.io component by extending it and creating your own methods.
import SelectComponent from 'formiojs/components/select/Select';
import Components from 'formiojs/components/Components';
export default class CustomSelect extends SelectComponent {
constructor(component, options, data) {
// Force all selects to use the html5 widget.
component.widget = 'html5';
super(component, options, data);
}
}
@travist
travist / CheckMatrix.js
Last active November 30, 2019 23:12
Angular 5 + Form.io Custom Component
/**
* This file shows how to create a custom component and register that within an Angular application.
*
* Get the base component class by referencing Formio.Components.components map.
*/
import BaseComponent from 'formiojs/components/base/Base';
import TableComponent from 'formiojs/components/table/Table';
import Components from 'formiojs/components/Components';
/**
import { Formio } from 'formiojs';
const formio = new Formio('https://myproject.form.io/myform/submission/[SUBMISSION_ID]');
formio.getDownloadUrl().then((downloadUrl) => {
console.log(downloadUrl);
});
@travist
travist / project-delete.js
Last active December 14, 2017 01:27
Clean up MongoDB for Form.io project
db.projects.find({_id: ObjectId('<PROJECT_ID>')}).forEach(function(project) {
print('Deleting roles for project ' + project._id);
db.roles.deleteMany({project: project._id});
print('Deleting form revisions for project ' + project._id);
db.formrevisions.deleteMany({project: project._id});
db.forms.find({project: project._id}).forEach(function(form) {
print('Deleting actions for form ' + form._id);
db.actions.deleteMany({form: form._id});
print('Deleting submissions for form ' + form._id);
db.submissions.deleteMany({form: form._id});
@travist
travist / migrate.js
Created November 6, 2017 19:49
Data migrate
import { async } from 'async';
import Formio from 'formiojs';
let destForm = new Formio('https://myproject.form.io/dest');
let formio = new Formio('https://myproject.form.io/myform');
formio.loadSubmissions({params: {
limit: 1000000
}}).then(function(submissions) {
async.eachSeries(submissions, (submission, next) => {
destForm.saveSubmission(submission).then(next);
{
"form": ObjectId("59ef44fb7c82831822dd0a75"),
"deleted": {
"$eq": null
},
"$or": [
{
"data.members": {
"$elemMatch": {"_id": "59ef8d025b59f1433dadaeb8"}
}
@travist
travist / report.js
Created October 16, 2017 18:33
Using JavaScript SDK for Report API
Formio.request('https://yourproject.form.io/projectname/report', 'POST', [
{
'$match': {
....
}
},
{
'$contains': {
}
@travist
travist / extended.js
Last active February 10, 2021 23:34
Extending Form.io Core Components
import {TextFieldComponent} from 'formiojs/build/components/textfield/TextField';
import Components from 'formiojs/build/components/index';
export class ExtendedTextField extends TextFieldComponent {
constructor(component, options, data) {
super(component, options, data);
}
createInput(container) {
let input = super.createInput(container);
if (this.component.custom.listen) {