Skip to content

Commit 75a0ae1

Browse files
Merge pull request #672 from Fliplet/release/ID-4818
https://weboo.atlassian.net/browse/ID-4818
2 parents dedb49e + 7fb757f commit 75a0ae1

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

js/components/timeStamp.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
Fliplet.FormBuilder.field('timeStamp', {
22
name: 'Time Stamp',
33
category: 'Date & time',
4-
submit: false,
54
props: {
5+
value: {
6+
type: Object
7+
},
68
placeholder: {
79
type: String
810
},
@@ -29,6 +31,29 @@ Fliplet.FormBuilder.field('timeStamp', {
2931
destroyed: function() {
3032
Fliplet.Hooks.off('afterFormSubmit', this.afterFormSubmit);
3133
},
34+
mounted: function() {
35+
this.value = {
36+
createdAt: this.createdAt,
37+
updatedAt: this.updatedAt
38+
};
39+
this.$emit('_input', this.name, this.value);
40+
},
41+
watch: {
42+
createdAt: function(val) {
43+
this.value = {
44+
createdAt: val,
45+
updatedAt: this.updatedAt
46+
};
47+
this.$emit('_input', this.name, this.value);
48+
},
49+
updatedAt: function(val) {
50+
this.value = {
51+
createdAt: this.createdAt,
52+
updatedAt: val
53+
};
54+
this.$emit('_input', this.name, this.value);
55+
}
56+
},
3257
methods: {
3358
afterFormSubmit: async function(data, form) {
3459
const fields = form.$instance.fields;
@@ -46,7 +71,12 @@ Fliplet.FormBuilder.field('timeStamp', {
4671

4772
const connection = await Fliplet.DataSources.connect(dataSourceId);
4873

49-
if (data.result.createdAt !== data.result.updatedAt && this.updatedAt) {
74+
if (data.result.createdAt !== data.result.updatedAt && this.updatedAt && this.createdAt) {
75+
connection.update(data.result.id, {
76+
'Created at': data.result.createdAt,
77+
'Last updated': data.result.updatedAt
78+
});
79+
} else if (data.result.createdAt !== data.result.updatedAt && this.updatedAt) {
5080
connection.update(data.result.id, {
5181
'Last updated': data.result.updatedAt
5282
});

js/libs/builder.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,18 @@ Fliplet().then(function() {
927927

928928
break;
929929

930+
case 'flTimeStamp':
931+
if (field.createdAt && !field.updatedAt) {
932+
fieldNames.push('Created at');
933+
} else if (!field.createdAt && field.updatedAt) {
934+
fieldNames.push('Last updated');
935+
} else {
936+
fieldNames.push('Created at');
937+
fieldNames.push('Last updated');
938+
}
939+
940+
break;
941+
930942
case 'flMatrix':
931943
_.forEach(field.rowOptions, function(row) {
932944
var val = row.id ? row.id : row.label;

js/libs/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Fliplet.FormBuilder = (function() {
222222
}
223223

224224
component.computed._isFormField = function() {
225-
return (this.showLabel || this.showLabel === undefined) && !(component.props._componentName.default === 'flCustomButton' || component.props._componentName.default === 'flTimeStamp');
225+
return (this.showLabel || this.showLabel === undefined) && component.props._componentName.default !== 'flCustomButton';
226226
};
227227

228228
component.computed._labelName = function() {

js/libs/form.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,14 @@ Fliplet().then(function() {
11781178
appendField(field.name, value ? value[0] : null);
11791179
appendField(`${field.name} (accuracy)`, value ? value[1] : null);
11801180
} else if (type === 'flTimeStamp') {
1181-
return;
1181+
if (value.createdAt && !value.updatedAt) {
1182+
appendField('Created at', new Date().toISOString());
1183+
} else if (!value.createdAt && value.updatedAt) {
1184+
appendField('Last updated', '');
1185+
} else if (value.createdAt && value.updatedAt) {
1186+
appendField('Created at', new Date().toISOString());
1187+
appendField('Last updated', '');
1188+
}
11821189
} else {
11831190
// Other inputs
11841191
appendField(field.name, value);

0 commit comments

Comments
 (0)