@nocobase/plugin-snapshot-field 0.9.1-alpha.2 → 0.9.2-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,69 +4,52 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SnapshotField = void 0;
7
-
8
7
  function _database() {
9
8
  const data = require("@nocobase/database");
10
-
11
9
  _database = function _database() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _sequelize() {
19
15
  const data = require("sequelize");
20
-
21
16
  _sequelize = function _sequelize() {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
29
-
30
22
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
31
-
32
23
  class SnapshotField extends _database().Field {
33
24
  constructor(...args) {
34
25
  var _this;
35
-
36
26
  super(...args);
37
27
  _this = this;
38
-
39
28
  this.createSnapshot = /*#__PURE__*/function () {
40
29
  var _ref = _asyncToGenerator(function* (model, {
41
30
  transaction,
42
31
  values
43
32
  }) {
44
33
  var _data;
45
-
46
34
  const _this$options = _this.options,
47
- name = _this$options.name,
48
- targetField = _this$options.targetField;
35
+ name = _this$options.name,
36
+ targetField = _this$options.targetField;
49
37
  const collectionName = _this.collection.name;
50
38
  const primaryKey = _this.collection.model.primaryKeyAttribute;
51
-
52
39
  if (!_this.collection.hasField(targetField)) {
53
40
  return;
54
41
  }
55
-
56
42
  const repository = _this.database.getRepository(`${collectionName}.${targetField}`, model.get(primaryKey));
57
-
58
43
  const appends = (_this.options.appends || []).filter(appendName => _this.database.getFieldByPath(`${repository.targetCollection.name}.${appendName}`));
59
44
  let data = yield repository.find({
60
45
  transaction,
61
46
  appends
62
47
  });
63
-
64
48
  if (Array.isArray(data)) {
65
49
  data = data.map(i => i.toJSON());
66
50
  } else if ((_data = data) === null || _data === void 0 ? void 0 : _data.toJSON) {
67
51
  data = data.toJSON();
68
52
  }
69
-
70
53
  yield model.update({
71
54
  [name]: {
72
55
  collectionName,
@@ -76,27 +59,21 @@ class SnapshotField extends _database().Field {
76
59
  transaction
77
60
  });
78
61
  });
79
-
80
62
  return function (_x, _x2) {
81
63
  return _ref.apply(this, arguments);
82
64
  };
83
65
  }();
84
66
  }
85
-
86
67
  get dataType() {
87
68
  return _sequelize().DataTypes.JSON;
88
69
  }
89
-
90
70
  bind() {
91
71
  super.bind();
92
72
  this.on('afterCreateWithAssociations', this.createSnapshot);
93
73
  }
94
-
95
74
  unbind() {
96
75
  super.unbind();
97
76
  this.off('afterCreateWithAssociations', this.createSnapshot);
98
77
  }
99
-
100
78
  }
101
-
102
79
  exports.SnapshotField = SnapshotField;
@@ -9,7 +9,5 @@ Object.defineProperty(exports, "default", {
9
9
  return _plugin.default;
10
10
  }
11
11
  });
12
-
13
12
  var _plugin = _interopRequireDefault(require("./plugin"));
14
-
15
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -4,96 +4,70 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.SnapshotFieldPlugin = void 0;
7
-
8
7
  function _server() {
9
8
  const data = require("@nocobase/server");
10
-
11
9
  _server = function _server() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _path() {
19
15
  const data = require("path");
20
-
21
16
  _path = function _path() {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  var _snapshotField = require("./fields/snapshot-field");
29
-
30
22
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
31
-
32
23
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
33
-
34
24
  class SnapshotFieldPlugin extends _server().Plugin {
35
25
  constructor(...args) {
36
26
  var _this;
37
-
38
27
  super(...args);
39
28
  _this = this;
40
-
41
29
  this.autoFillTargetCollection = /*#__PURE__*/function () {
42
30
  var _ref = _asyncToGenerator(function* (model) {
43
31
  const _model$get = model.get(),
44
- collectionName = _model$get.collectionName,
45
- targetField = _model$get.targetField;
46
-
32
+ collectionName = _model$get.collectionName,
33
+ targetField = _model$get.targetField;
47
34
  const collection = _this.db.getCollection(collectionName);
48
-
49
35
  if (!collection) {
50
36
  return;
51
37
  }
52
-
53
38
  const field = collection.getField(targetField);
54
-
55
39
  if (field === null || field === void 0 ? void 0 : field.target) {
56
40
  model.set('targetCollection', field.target);
57
41
  }
58
42
  });
59
-
60
43
  return function (_x) {
61
44
  return _ref.apply(this, arguments);
62
45
  };
63
46
  }();
64
47
  }
65
-
66
48
  afterAdd() {}
67
-
68
49
  beforeLoad() {
69
50
  var _this2 = this;
70
-
71
51
  return _asyncToGenerator(function* () {
72
52
  const collectionHandler = /*#__PURE__*/function () {
73
53
  var _ref2 = _asyncToGenerator(function* (model, {
74
54
  transaction
75
55
  }) {
76
56
  var _collectionDoc$fields;
77
-
78
57
  const collectionDoc = model.toJSON();
79
-
80
58
  const collectionsHistoryRepository = _this2.app.db.getRepository('collectionsHistory');
81
-
82
59
  const fieldsHistoryRepository = _this2.app.db.getRepository('fieldsHistory');
83
-
84
60
  const existCollection = yield collectionsHistoryRepository.findOne({
85
61
  filter: {
86
62
  name: collectionDoc.name
87
63
  }
88
64
  });
89
-
90
65
  if (existCollection) {
91
66
  // 删除表和其关联字段
92
67
  yield existCollection.destroy({
93
68
  transaction
94
69
  });
95
70
  }
96
-
97
71
  yield collectionsHistoryRepository.create({
98
72
  values: collectionDoc,
99
73
  transaction
@@ -103,80 +77,62 @@ class SnapshotFieldPlugin extends _server().Plugin {
103
77
  transaction
104
78
  });
105
79
  });
106
-
107
80
  return function collectionHandler(_x2, _x3) {
108
81
  return _ref2.apply(this, arguments);
109
82
  };
110
83
  }();
111
-
112
84
  _this2.app.db.on('collections.afterCreateWithAssociations', collectionHandler);
113
-
114
85
  const fieldHandler = /*#__PURE__*/function () {
115
86
  var _ref3 = _asyncToGenerator(function* (model, {
116
87
  transaction
117
88
  }) {
118
89
  const fieldDoc = model.get();
119
-
120
90
  const fieldsHistoryRepository = _this2.app.db.getRepository('fieldsHistory');
121
-
122
91
  const existField = yield fieldsHistoryRepository.findOne({
123
92
  filter: {
124
93
  name: fieldDoc.name,
125
94
  collectionName: fieldDoc.collectionName
126
95
  }
127
96
  });
128
-
129
97
  if (existField) {
130
98
  yield existField.destroy({
131
99
  transaction
132
100
  });
133
101
  }
134
-
135
102
  yield fieldsHistoryRepository.create({
136
103
  values: JSON.parse(JSON.stringify(fieldDoc)),
137
104
  transaction
138
105
  });
139
106
  });
140
-
141
107
  return function fieldHandler(_x4, _x5) {
142
108
  return _ref3.apply(this, arguments);
143
109
  };
144
110
  }();
145
-
146
111
  _this2.app.db.on('fields.afterCreateWithAssociations', fieldHandler);
147
-
148
112
  _this2.app.db.on('fields.beforeCreate', _this2.autoFillTargetCollection);
149
113
  })();
150
114
  }
151
-
152
115
  load() {
153
116
  var _this3 = this;
154
-
155
117
  return _asyncToGenerator(function* () {
156
118
  // 导入 collection
157
119
  yield _this3.db.import({
158
120
  directory: (0, _path().resolve)(__dirname, 'collections')
159
121
  });
160
-
161
122
  _this3.app.db.registerFieldTypes({
162
123
  snapshot: _snapshotField.SnapshotField
163
124
  });
164
-
165
125
  _this3.app.acl.allow('collectionsHistory', 'list', 'loggedIn');
166
126
  })();
167
- } // 初始化安装的时候
168
-
169
-
127
+ }
128
+ // 初始化安装的时候
170
129
  install(options) {
171
130
  var _this4 = this;
172
-
173
131
  return _asyncToGenerator(function* () {
174
132
  yield _this4.app.db.sequelize.transaction( /*#__PURE__*/function () {
175
133
  var _ref4 = _asyncToGenerator(function* (transaction) {
176
134
  const collectionsRepository = _this4.app.db.getRepository('collections');
177
-
178
135
  const collectionsHistoryRepository = _this4.app.db.getRepository('collectionsHistory');
179
-
180
136
  if ((yield collectionsHistoryRepository.find()).length === 0) {
181
137
  const collectionsModels = yield collectionsRepository.find();
182
138
  yield collectionsHistoryRepository.createMany({
@@ -184,11 +140,8 @@ class SnapshotFieldPlugin extends _server().Plugin {
184
140
  transaction
185
141
  });
186
142
  }
187
-
188
143
  const fieldsRepository = _this4.app.db.getRepository('fields');
189
-
190
144
  const fieldsHistoryRepository = _this4.app.db.getRepository('fieldsHistory');
191
-
192
145
  if ((yield fieldsHistoryRepository.find()).length === 0) {
193
146
  const fieldsModels = yield fieldsRepository.find();
194
147
  yield fieldsHistoryRepository.createMany({
@@ -197,28 +150,22 @@ class SnapshotFieldPlugin extends _server().Plugin {
197
150
  });
198
151
  }
199
152
  });
200
-
201
153
  return function (_x6) {
202
154
  return _ref4.apply(this, arguments);
203
155
  };
204
156
  }());
205
157
  })();
206
158
  }
207
-
208
159
  afterEnable() {
209
160
  return _asyncToGenerator(function* () {})();
210
161
  }
211
-
212
162
  afterDisable() {
213
163
  return _asyncToGenerator(function* () {})();
214
164
  }
215
-
216
165
  remove() {
217
166
  return _asyncToGenerator(function* () {})();
218
167
  }
219
-
220
168
  }
221
-
222
169
  exports.SnapshotFieldPlugin = SnapshotFieldPlugin;
223
170
  var _default = SnapshotFieldPlugin;
224
171
  exports.default = _default;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-snapshot-field",
3
- "version": "0.9.1-alpha.2",
3
+ "version": "0.9.2-alpha.2",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "devDependencies": {
9
- "@nocobase/server": "0.9.1-alpha.2",
10
- "@nocobase/test": "0.9.1-alpha.2"
9
+ "@nocobase/server": "0.9.2-alpha.2",
10
+ "@nocobase/test": "0.9.2-alpha.2"
11
11
  },
12
- "gitHead": "d588a68eca4feed4642a4cb317301011266fe5c9"
12
+ "gitHead": "1a0de6908b2b1854bdf434fcafa8909cb65bb8a3"
13
13
  }
@@ -3,21 +3,18 @@ import {
3
3
  CollectionManagerProvider,
4
4
  registerField,
5
5
  SchemaComponentOptions,
6
- SchemaInitializerContext,
7
- SchemaInitializerProvider,
6
+ SchemaInitializerProvider
8
7
  } from '@nocobase/client';
9
- import React, { useContext, useEffect } from 'react';
8
+ import React, { useEffect } from 'react';
9
+ import { AppendsTreeSelect } from './components/AppendsTreeSelect';
10
+ import { SnapshotOwnerCollectionFieldsSelect } from './components/SnapshotOwnerCollectionFieldsSelect';
10
11
  import { snapshot } from './interface';
11
- import { SnapshotRecordPicker } from './SnapshotRecordPicker';
12
12
  import { SnapshotBlockInitializers } from './SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializers';
13
13
  import { SnapshotBlockInitializersDetailItem } from './SnapshotBlock/SnapshotBlockInitializers/SnapshotBlockInitializersDetailItem';
14
14
  import { SnapshotBlockProvider } from './SnapshotBlock/SnapshotBlockProvider';
15
- import { AppendsTreeSelect } from './components/AppendsTreeSelect';
16
- import { SnapshotOwnerCollectionFieldsSelect } from './components/SnapshotOwnerCollectionFieldsSelect';
15
+ import { SnapshotRecordPicker } from './SnapshotRecordPicker';
17
16
 
18
17
  export default React.memo((props) => {
19
- const initializers = useContext(SchemaInitializerContext);
20
-
21
18
  useEffect(() => {
22
19
  registerField(snapshot.group, snapshot.name as string, snapshot);
23
20
  }, []);
@@ -31,7 +28,6 @@ export default React.memo((props) => {
31
28
  <CollectionHistoryProvider>
32
29
  <SchemaInitializerProvider
33
30
  initializers={{
34
- ...initializers,
35
31
  SnapshotBlockInitializers,
36
32
  }}
37
33
  >
@@ -0,0 +1,12 @@
1
+ export default {
2
+ Detail: 'Detalhes',
3
+ Snapshot: 'Fotografia',
4
+ 'View record': 'Visualizar registro',
5
+ 'Add block': 'Adicionar bloco',
6
+ 'Allow linking to multiple records': 'Permitir vinculação a vários registros',
7
+ 'When adding a new record, create a snapshot for its relational record and save in the current record. The snapshot is not updated when the record is subsequently updated.':
8
+ 'Ao adicionar um novo registro, crie uma imagem instantânea para o registro relacionado e salve no registro atual. A imagem instantânea não é atualizada quando o registro é posteriormente atualizado.',
9
+ 'The association field to snapshot': 'O campo de associação para criar imagem instantânea',
10
+ "Snapshot the snapshot's association fields": "Criar imagem instantânea para os campos de associação da imagem instantânea",
11
+ 'Please select': 'Por favor, selecione',
12
+ };
@@ -1,7 +1,7 @@
1
1
  import { CollectionOptions } from '@nocobase/database';
2
2
 
3
3
  export default {
4
- namespace: 'snapshot-field',
4
+ namespace: 'snapshot-field.snapshot-field',
5
5
  duplicator: 'required',
6
6
  name: 'collectionsHistory',
7
7
  title: '数据表历史',
@@ -1,7 +1,7 @@
1
1
  import { CollectionOptions } from '@nocobase/database';
2
2
 
3
3
  export default {
4
- namespace: 'snapshot-field',
4
+ namespace: 'snapshot-field.snapshot-field',
5
5
  duplicator: 'required',
6
6
  name: 'fieldsHistory',
7
7
  title: '{{t("Fields history")}}',
@@ -60,12 +60,12 @@ export default {
60
60
  sourceKey: 'key',
61
61
  foreignKey: 'reverseKey',
62
62
  },
63
- {
64
- type: 'belongsTo',
65
- name: 'uiSchema',
66
- target: 'uiSchemas',
67
- foreignKey: 'uiSchemaUid',
68
- },
63
+ // {
64
+ // type: 'belongsTo',
65
+ // name: 'uiSchema',
66
+ // target: 'uiSchemas',
67
+ // foreignKey: 'uiSchemaUid',
68
+ // },
69
69
  {
70
70
  type: 'json',
71
71
  name: 'options',