@mongoosejs/studio 0.0.4 → 0.0.6

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.
@@ -6,6 +6,8 @@ const client = axios.create({
6
6
  baseURL: config__baseURL
7
7
  });
8
8
 
9
+ window.apiClient = client;
10
+
9
11
  if (config__isLambda) {
10
12
  exports.Model = {
11
13
  deleteDocument(params) {
@@ -108,7 +108,16 @@
108
108
  width: calc(100% - 1em);
109
109
  }
110
110
 
111
- .sort-arrow {
111
+ .models .sort-arrow {
112
112
  padding-left: 10px;
113
113
  padding-right: 10px;
114
+ }
115
+
116
+ .models .loader {
117
+ width: 100%;
118
+ text-align: center;
119
+ }
120
+
121
+ .models .loader img {
122
+ height: 4em;
114
123
  }
@@ -7,7 +7,7 @@
7
7
  </router-link>
8
8
  </div>
9
9
  </div>
10
- <div class="documents">
10
+ <div class="documents" ref="documentsList">
11
11
  <div>
12
12
  <div class="documents-menu">
13
13
  <div class="search-input">
@@ -46,6 +46,9 @@
46
46
  </tr>
47
47
  </tbody>
48
48
  </table>
49
+ <div v-if="true" class="loader">
50
+ <img src="images/loader.gif">
51
+ </div>
49
52
  </div>
50
53
  <modal v-if="shouldShowExportModal">
51
54
  <template v-slot:body>
@@ -25,21 +25,36 @@ module.exports = app => app.component('models', {
25
25
  searchText: '',
26
26
  shouldShowExportModal: false,
27
27
  shouldExport: {},
28
- sortBy: {}
28
+ sortBy: {},
29
+ query: {},
30
+ scrollHeight: 0,
31
+ limit: 50,
32
+ interval: null
29
33
  }),
30
34
  created() {
31
35
  this.currentModel = this.model;
32
36
  },
37
+ beforeDestroy() {
38
+ document.removeEventListener('scroll', () => this.onScroll(), true);
39
+ },
33
40
  async mounted() {
41
+ document.addEventListener('scroll', () => this.onScroll(), true);
34
42
  this.models = await api.Model.listModels().then(res => res.models);
35
43
  if (this.currentModel == null && this.models.length > 0) {
36
44
  this.currentModel = this.models[0];
37
45
  }
46
+ this.query = Object.assign({}, this.$route.query); // important that this is here before the if statements
38
47
  if (this.$route.query?.search) {
39
48
  this.searchText = this.$route.query.search;
40
49
  this.filter = eval(`(${this.$route.query.search})`);
41
50
  this.filter = EJSON.stringify(this.filter);
42
51
  }
52
+ if (this.$route.query?.sort) {
53
+ const sort = eval(`(${this.$route.query.sort})`);
54
+ const path = Object.keys(sort)[0];
55
+ const num = Object.values(sort)[0];
56
+ this.sortDocs(num, path);
57
+ }
43
58
 
44
59
  if (this.currentModel != null) {
45
60
  await this.getDocuments();
@@ -48,16 +63,32 @@ module.exports = app => app.component('models', {
48
63
  this.status = 'loaded';
49
64
  },
50
65
  methods: {
66
+ async onScroll() {
67
+ if (this.status === 'loading') {
68
+ return;
69
+ }
70
+ const container = this.$refs.documentsList;
71
+ if (container.scrollHeight - container.clientHeight - 100 < container.scrollTop) {
72
+ this.status = 'loading';
73
+ this.limit += 50;
74
+ await this.getDocuments();
75
+ this.status = 'loaded';
76
+ }
77
+ },
51
78
  async sortDocs(num, path) {
52
79
  let sorted = false;
53
80
  if (this.sortBy[path] == num) {
54
81
  sorted = true;
82
+ delete this.query.sort;
83
+ this.$router.push({ query: this.query });
55
84
  }
56
85
  for (const key in this.sortBy) {
57
86
  delete this.sortBy[key];
58
87
  }
59
88
  if (!sorted) {
60
89
  this.sortBy[path] = num;
90
+ this.query.sort = `{${path}:${num}}`
91
+ this.$router.push({ query: this.query });
61
92
  }
62
93
  await this.getDocuments();
63
94
  },
@@ -65,10 +96,12 @@ module.exports = app => app.component('models', {
65
96
  if (this.searchText && Object.keys(this.searchText).length) {
66
97
  this.filter = eval(`(${this.searchText})`);
67
98
  this.filter = EJSON.stringify(this.filter);
68
- this.$router.push({ path: this.$route.path, query: { search: this.searchText }})
99
+ this.query.search = this.searchText;
100
+ this.$router.push({ path: this.$route.path, query: this.query })
69
101
  } else {
70
102
  this.filter = {};
71
- this.$router.push({ path: this.$route.path });
103
+ delete this.query.search;
104
+ this.$router.push({ path: this.$route.path, query: this.query });
72
105
  }
73
106
  await this.getDocuments();
74
107
  },
@@ -76,7 +109,8 @@ module.exports = app => app.component('models', {
76
109
  const { docs, schemaPaths, numDocs } = await api.Model.getDocuments({
77
110
  model: this.currentModel,
78
111
  filter: this.filter,
79
- sort: this.sortBy
112
+ sort: this.sortBy,
113
+ limit: this.limit
80
114
  });
81
115
  this.documents = docs;
82
116
  this.schemaPaths = Object.keys(schemaPaths).sort((k1, k2) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongoosejs/studio",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "dependencies": {
5
5
  "archetype": "0.13.0",
6
6
  "csv-stringify": "6.3.0",