@mongoosejs/studio 0.0.14 → 0.0.16

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  const Archetype = require('archetype');
4
4
  const removeSpecifiedPaths = require('../../helpers/removeSpecifiedPaths');
5
- const EJSON = require('ejson');
5
+ const { EJSON } = require('bson')
6
6
 
7
7
  const GetDocumentsParams = new Archetype({
8
8
  model: {
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const vanillatoasts = require('vanillatoasts');
4
+
3
5
  const app = Vue.createApp({
4
6
  template: '<app-component />'
5
7
  });
@@ -31,7 +33,15 @@ app.component('app-component', {
31
33
  <router-view :key="$route.fullPath" />
32
34
  </div>
33
35
  </div>
34
- `
36
+ `,
37
+ errorCaptured(err) {
38
+ vanillatoasts.create({
39
+ title: `Error: ${err.message}`,
40
+ icon: 'images/failure.jpg',
41
+ timeout: 10000,
42
+ positionClass: 'bottomRight'
43
+ });
44
+ }
35
45
  });
36
46
 
37
47
  const routes = require('./routes');
@@ -46,6 +46,8 @@
46
46
 
47
47
  .modal-body {
48
48
  margin: 20px 0;
49
+ max-height: calc(100vh - 40px - 60px - 10px);
50
+ overflow: auto;
49
51
  }
50
52
 
51
53
  .modal__button--default {
@@ -80,4 +82,4 @@
80
82
  right: 0.25em;
81
83
  top: 0.25em;
82
84
  cursor: pointer;
83
- }
85
+ }
@@ -5,6 +5,11 @@
5
5
  min-height: calc(100% - 56px);
6
6
  }
7
7
 
8
+ .models button.gray {
9
+ color: black;
10
+ background-color: #eee;
11
+ }
12
+
8
13
  .models .model-selector {
9
14
  background-color: #eee;
10
15
  flex-grow: 0;
@@ -120,4 +125,14 @@
120
125
 
121
126
  .models .loader img {
122
127
  height: 4em;
128
+ }
129
+
130
+ .models .documents .buttons {
131
+ display: inline-flex;
132
+ justify-content: space-around;
133
+ align-items: baseline;
134
+ }
135
+
136
+ .models .documents .buttons button:not(:last-child) {
137
+ margin-right: 8px;
123
138
  }
@@ -19,13 +19,14 @@
19
19
  </div>
20
20
  <div class="buttons">
21
21
  <button @click="shouldShowExportModal = true">Export</button>
22
+ <button @click="shouldShowFieldModal = true">Fields</button>
22
23
  </div>
23
24
  </div>
24
25
  </div>
25
26
  <div class="documents-container">
26
27
  <table>
27
28
  <thead>
28
- <th v-for="path in schemaPaths">
29
+ <th v-for="path in filteredPaths">
29
30
  {{path.path}}
30
31
  <span class="path-type">
31
32
  ({{(path.instance || 'unknown')}})
@@ -36,7 +37,7 @@
36
37
  </thead>
37
38
  <tbody>
38
39
  <tr v-for="document in documents" @click="$router.push('/model/' + currentModel + '/document/' + document._id)" :key="document._id">
39
- <td v-for="schemaPath in schemaPaths">
40
+ <td v-for="schemaPath in filteredPaths">
40
41
  <component
41
42
  :is="getComponentForPath(schemaPath)"
42
43
  :value="getValueForPath(document, schemaPath.path)"
@@ -61,5 +62,20 @@
61
62
  </export-query-results>
62
63
  </template>
63
64
  </modal>
65
+ <modal v-if="shouldShowFieldModal">
66
+ <template v-slot:body>
67
+ <div class="modal-exit" @click="shouldShowFieldModal = false; selectedPaths = [...filteredPaths];">&times;</div>
68
+ <div v-for="(path, index) in schemaPaths" :key="index" style="margin-bottom: 0.5em">
69
+ <input type="checkbox" :id="'path.path'+index" @change="addOrRemove(path)" :value="path.path" :checked="isSelected(path.path)" />
70
+ <label :for="'path' + index">{{path.path}}</label>
71
+ </div>
72
+ <div style="margin-top: 1em">
73
+ <button type="submit" @click="filterDocuments()" style="color: black;margin-right: 0.5em">Filter Selection</button>
74
+ <button type="submit" @click="deselectAll()" class="gray" style="margin-right: 0.5em">Deselect All</button>
75
+ <button type="submit" @click="resetDocuments()" class="gray">Cancel</button>
76
+
77
+ </div>
78
+ </template>
79
+ </modal>
64
80
  </div>
65
81
  </div>
@@ -2,8 +2,14 @@
2
2
 
3
3
  const api = require('../api');
4
4
  const template = require('./models.html');
5
- const EJSON = require('ejson');
6
5
  const mpath = require('mpath');
6
+ const { BSON, EJSON } = require('bson');
7
+
8
+ const ObjectId = new Proxy(BSON.ObjectId, {
9
+ apply (target, thisArg, argumentsList) {
10
+ return new target(...argumentsList);
11
+ }
12
+ });
7
13
 
8
14
  const appendCSS = require('../appendCSS');
9
15
 
@@ -19,6 +25,8 @@ module.exports = app => app.component('models', {
19
25
  currentModel: null,
20
26
  documents: [],
21
27
  schemaPaths: [],
28
+ filteredPaths: [],
29
+ selectedPaths: [],
22
30
  numDocuments: 0,
23
31
  status: 'loading',
24
32
  loadedAllDocs: false,
@@ -27,6 +35,7 @@ module.exports = app => app.component('models', {
27
35
  filter: null,
28
36
  searchText: '',
29
37
  shouldShowExportModal: false,
38
+ shouldShowFieldModal: false,
30
39
  shouldExport: {},
31
40
  sortBy: {},
32
41
  query: {},
@@ -62,6 +71,16 @@ module.exports = app => app.component('models', {
62
71
  await this.getDocuments();
63
72
  }
64
73
 
74
+ const hashUrl = window.location.hash.replace(/^#/, '');
75
+ if (hashUrl.indexOf('?') !== -1) {
76
+ const searchParams = new URLSearchParams(
77
+ hashUrl.slice(hashUrl.indexOf('?') + 1)
78
+ );
79
+ if (searchParams.has('fields')) {
80
+ this.filteredPaths = searchParams.get('fields').split(',').map(path => ({ path }));
81
+ }
82
+ }
83
+
65
84
  this.status = 'loaded';
66
85
  },
67
86
  methods: {
@@ -79,7 +98,6 @@ module.exports = app => app.component('models', {
79
98
  skip: this.documents.length,
80
99
  limit
81
100
  });
82
- console.log('FX', docs.length, limit)
83
101
  if (docs.length < limit) {
84
102
  this.loadedAllDocs = true;
85
103
  }
@@ -143,6 +161,55 @@ module.exports = app => app.component('models', {
143
161
  for (const { path } of this.schemaPaths) {
144
162
  this.shouldExport[path] = true;
145
163
  }
164
+
165
+ this.filteredPaths = [...this.schemaPaths];
166
+ this.selectedPaths = [...this.schemaPaths];
167
+ },
168
+ addOrRemove(path) {
169
+ const exists = this.selectedPaths.findIndex(x => x.path == path.path);
170
+ if (exists > 0) { // remove
171
+ this.selectedPaths.splice(exists, 1);
172
+ } else { // add
173
+ this.selectedPaths.push(path);
174
+ this.selectedPaths = Object.keys(this.selectedPaths).sort((k1, k2) => {
175
+ if (k1 === '_id' && k2 !== '_id') {
176
+ return -1;
177
+ }
178
+ if (k1 !== '_id' && k2 === '_id') {
179
+ return 1;
180
+ }
181
+ return 0;
182
+ }).map(key => this.selectedPaths[key]);
183
+ }
184
+ },
185
+ filterDocuments() {
186
+ this.filteredPaths = [...this.selectedPaths];
187
+ this.shouldShowFieldModal = false;
188
+ const selectedParams = this.filteredPaths.map(x => x.path).join(',');
189
+
190
+ const hashUrl = window.location.hash.replace(/^#/, '');
191
+ if (hashUrl.indexOf('?') === -1) {
192
+ window.history.pushState({}, '', window.location.pathname + '#' + hashUrl + '?fields=' + selectedParams);
193
+ } else {
194
+ const searchParams = new URLSearchParams(
195
+ hashUrl.indexOf('?') === -1 ? '' : hashUrl.slice(hashUrl.indexOf('?') + 1)
196
+ );
197
+ const hashUrlWithoutSearchParams = hashUrl.slice(0, hashUrl.indexOf('?'));
198
+
199
+ searchParams.set('fields', selectedParams);
200
+ window.history.pushState({}, '', window.location.pathname + '#' + hashUrlWithoutSearchParams + '?' + searchParams);
201
+ }
202
+
203
+ },
204
+ resetDocuments() {
205
+ this.selectedPaths = [...this.filteredPaths];
206
+ this.shouldShowFieldModal = false;
207
+ },
208
+ deselectAll() {
209
+ this.selectedPaths = [];
210
+ },
211
+ isSelected(path) {
212
+ return this.selectedPaths.find(x => x.path == path);
146
213
  },
147
214
  getComponentForPath(schemaPath) {
148
215
  if (schemaPath.instance === 'Array') {
@@ -179,4 +246,4 @@ module.exports = app => app.component('models', {
179
246
  this.edittingDoc = null;
180
247
  }
181
248
  }
182
- });
249
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongoosejs/studio",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "dependencies": {
5
5
  "archetype": "0.13.0",
6
6
  "csv-stringify": "6.3.0",
@@ -10,6 +10,7 @@
10
10
  "vanillatoasts": "^1.6.0"
11
11
  },
12
12
  "peerDependencies": {
13
+ "bson": "^5.5.1",
13
14
  "express": "4.x",
14
15
  "mongoose": "7.x || 8.0.0-rc0 || 8.x"
15
16
  },