Skip to content

Commit 9c612a7

Browse files
authored
Merge pull request #40 from formio/FIO-7245-migrate-resource-to-contrib
FIO-7245: Moved Resource component to the contrib library
2 parents 39ca744 + 8b55c1a commit 9c612a7

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed

src/components/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import checkmatrix from './CheckMatrix/CheckMatrix';
2+
import resource from './resource/Resource';
23
import tree from './tree/Tree';
3-
44
export default {
55
checkmatrix,
6+
resource,
67
tree,
78
};
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Components } from 'formiojs';
2+
import ResourceEditDisplay from './editForm/Resource.edit.display';
3+
4+
export default function(...extend) {
5+
return Components.baseEditForm([
6+
{
7+
key: 'display',
8+
components: ResourceEditDisplay
9+
},
10+
], ...extend);
11+
}

src/components/resource/Resource.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Components } from 'formiojs';
2+
const SelectComponent = (Components.components as any).select;
3+
import editForm from './Resource.form';
4+
5+
export default class ResourceComponent extends SelectComponent {
6+
static editForm = editForm;
7+
8+
static schema(...extend) {
9+
return SelectComponent.schema({
10+
type: 'resource',
11+
label: 'Resource',
12+
key: 'resource',
13+
dataSrc: 'resource',
14+
resource: '',
15+
project: '',
16+
template: '<span>{{ item.data }}</span>',
17+
}, ...extend);
18+
}
19+
20+
static get builderInfo() {
21+
return {
22+
title: 'Resource',
23+
icon: 'files-o',
24+
weight: 90,
25+
documentation: '/userguide/form-building/form-components#resource',
26+
schema: ResourceComponent.schema(),
27+
};
28+
}
29+
30+
constructor(...args) {
31+
super(...args);
32+
}
33+
34+
init() {
35+
super.init();
36+
this.component.dataSrc = 'resource';
37+
this.component.data = {
38+
resource: this.component.resource,
39+
};
40+
}
41+
42+
get defaultSchema() {
43+
return ResourceComponent.schema();
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
export default [
2+
{
3+
key: 'resourceInfo',
4+
weight: -10,
5+
type: 'htmlelement',
6+
tag: 'div',
7+
className: 'alert alert-danger',
8+
content: 'This component has been deprecated and will be removed in a future version of Formio.js.',
9+
},
10+
{
11+
type: 'select',
12+
input: true,
13+
dataSrc: 'url',
14+
data: {
15+
url: '/form?type=resource&limit=1000000&select=_id,title',
16+
},
17+
authenticate: true,
18+
template: '<span>{{ item.title }}</span>',
19+
valueProperty: '_id',
20+
label: 'Resource',
21+
key: 'resource',
22+
weight: 50,
23+
tooltip: 'The resource to be used with this field.',
24+
},
25+
{
26+
type: 'tags',
27+
input: true,
28+
key: 'selectFields',
29+
label: 'Select Fields',
30+
tooltip: 'The properties on the resource to return as part of the options. If left blank, all properties will be returned.',
31+
placeholder: 'Enter the fields to select.',
32+
weight: 51,
33+
},
34+
{
35+
type: 'tags',
36+
input: true,
37+
key: 'searchFields',
38+
label: 'Search Fields',
39+
tooltip: 'A list of search filters based on the fields of the resource. See the <a target=\'_blank\' href=\'https://github.com/travist/resourcejs#filtering-the-results\'>Resource.js documentation</a> for the format of these filters.',
40+
placeholder: 'The fields to query on the server',
41+
weight: 52,
42+
},
43+
{
44+
type: 'textfield',
45+
input: true,
46+
key: 'filter',
47+
label: 'Filter Query',
48+
weight: 53,
49+
description: 'The filter query for results.',
50+
tooltip: 'Use this to provide additional filtering using query parameters.',
51+
},
52+
{
53+
type: 'textfield',
54+
input: true,
55+
key: 'sort',
56+
label: 'Sort Query',
57+
weight: 53,
58+
description: 'The sort query for results',
59+
tooltip: 'Use this to provide additional sorting using query parameters',
60+
},
61+
{
62+
type: 'textarea',
63+
input: true,
64+
key: 'template',
65+
label: 'Item Template',
66+
editor: 'ace',
67+
as: 'html',
68+
rows: 3,
69+
weight: 53,
70+
tooltip: 'The HTML template for the result data items.',
71+
},
72+
{
73+
type: 'checkbox',
74+
input: true,
75+
weight: 54,
76+
key: 'addResource',
77+
label: 'Add Resource',
78+
tooltip: 'Allows to create a new resource while entering a submission.',
79+
conditional: {
80+
json: { '===': [{ var: 'data.dataSrc' }, 'resource'] },
81+
},
82+
},
83+
{
84+
type: 'textfield',
85+
label: 'Add Resource Label',
86+
key: 'addResourceLabel',
87+
tooltip: 'Set the text of the Add Resource button.',
88+
placeholder: 'Add Resource',
89+
weight: 55,
90+
input: true,
91+
conditional: {
92+
json: {
93+
and: [
94+
{ '===': [{ var: 'data.dataSrc' }, 'resource'] },
95+
{ '!!': { var: 'data.addResource' } },
96+
],
97+
},
98+
},
99+
},
100+
];

0 commit comments

Comments
 (0)