diff --git a/app/components/icons/pencil-outline.js b/app/components/icons/pencil-outline.js
new file mode 100644
index 0000000..a9aba4a
--- /dev/null
+++ b/app/components/icons/pencil-outline.js
@@ -0,0 +1 @@
+export { PencilOutline as default } from 'ember-mdi';
diff --git a/app/controllers/admin/indexes/item/documents.js b/app/controllers/admin/indexes/item/documents.js
index 7840ea8..b506742 100644
--- a/app/controllers/admin/indexes/item/documents.js
+++ b/app/controllers/admin/indexes/item/documents.js
@@ -1,66 +1,3 @@
import Controller from '@ember/controller';
-import { action } from '@ember/object';
-import { tracked } from '@glimmer/tracking';
-import { Magnify, Table, MapOutline } from 'ember-mdi';
-export default class AdminIndexesItemDocumentsController extends Controller {
- @tracked q = null;
- @tracked limit = 20;
- @tracked page = 1;
- @tracked dataView = 'table';
- @tracked sort;
-
- queryParams = ['q', 'page', 'limit', 'sort'];
-
- Magnify = Magnify;
-
- // key: view name, value: icon
- views = {
- table: Table,
- map: MapOutline,
- };
-
- get fromHits() {
- return 1 + this.model.data.offset;
- }
-
- get toHits() {
- return this.model.data.offset + this.model.data.hits.length;
- }
-
- get sortedFields() {
- const fields = Object.keys(this.model.stats.fieldDistribution);
- const primaryKey = this.model.index.primaryKey ?? 'id';
- const sortedArray = fields
- .filter((item) => item !== primaryKey)
- .sort((a, b) => {
- if (a > b || a.charAt(0) === '_') {
- return 1;
- }
-
- if (a < b) {
- return -1;
- }
-
- return 0;
- });
-
- return [primaryKey].concat(sortedArray);
- }
-
- @action
- searchTextChanged(value) {
- this.q = value === '' ? null : value;
- }
-
- @action
- onSort(newSort) {
- if (`${newSort}:desc` === this.sort) {
- this.sort = null;
- } else if (`${newSort}:asc` === this.sort) {
- this.sort = `${newSort}:desc`;
- } else {
- this.sort = `${newSort}:asc`;
- }
- }
-}
+export default class AdminIndexesItemDocumentsController extends Controller {}
diff --git a/app/controllers/admin/indexes/item/documents/index.js b/app/controllers/admin/indexes/item/documents/index.js
new file mode 100644
index 0000000..474bd85
--- /dev/null
+++ b/app/controllers/admin/indexes/item/documents/index.js
@@ -0,0 +1,66 @@
+import Controller from '@ember/controller';
+import { action } from '@ember/object';
+import { tracked } from '@glimmer/tracking';
+import { Magnify, Table, MapOutline } from 'ember-mdi';
+
+export default class AdminIndexesItemDocumentsIndexController extends Controller {
+ @tracked q = null;
+ @tracked limit = 20;
+ @tracked page = 1;
+ @tracked dataView = 'table';
+ @tracked sort;
+
+ queryParams = ['q', 'page', 'limit', 'sort'];
+
+ Magnify = Magnify;
+
+ // key: view name, value: icon
+ views = {
+ table: Table,
+ map: MapOutline,
+ };
+
+ get fromHits() {
+ return 1 + this.model.data.offset;
+ }
+
+ get toHits() {
+ return this.model.data.offset + this.model.data.hits.length;
+ }
+
+ get sortedFields() {
+ const fields = Object.keys(this.model.stats.fieldDistribution);
+ const primaryKey = this.model.index.primaryKey ?? 'id';
+ const sortedArray = fields
+ .filter((item) => item !== primaryKey)
+ .sort((a, b) => {
+ if (a > b || a.charAt(0) === '_') {
+ return 1;
+ }
+
+ if (a < b) {
+ return -1;
+ }
+
+ return 0;
+ });
+
+ return [primaryKey].concat(sortedArray);
+ }
+
+ @action
+ searchTextChanged(value) {
+ this.q = value === '' ? null : value;
+ }
+
+ @action
+ onSort(newSort) {
+ if (`${newSort}:desc` === this.sort) {
+ this.sort = null;
+ } else if (`${newSort}:asc` === this.sort) {
+ this.sort = `${newSort}:desc`;
+ } else {
+ this.sort = `${newSort}:asc`;
+ }
+ }
+}
diff --git a/app/models/document.js b/app/models/document.js
new file mode 100644
index 0000000..881f9d4
--- /dev/null
+++ b/app/models/document.js
@@ -0,0 +1,21 @@
+import query from '../utils/query';
+
+export default class Document {
+ constructor(data = {}) {
+ for (const key in data) {
+ this[key] = data[key];
+ }
+ }
+
+ // get path() {
+ // return `${this.#index.path}/documents/${this.documentId}`;
+ // }
+
+ // get isNew() {
+ // return Boolean(!this.documentId);
+ // }
+
+ // get documentId() {
+ // return this[this.#index.primaryKey];
+ // }
+}
diff --git a/app/models/index.js b/app/models/index.js
index 5a28adb..23bc2b3 100644
--- a/app/models/index.js
+++ b/app/models/index.js
@@ -1,22 +1,16 @@
import query from '../utils/query';
// import { TrackedArray } from 'tracked-built-ins';
// import { trackedFunction } from 'ember-resources/util/function';
+import Document from './document';
export default class Index {
- // stats = trackedFunction(this, () => query(`${this.indexPath}/stats`));
- // displayedAttributes = trackedFunction(this, () =>
- // query(`${this.indexPath}/settings/displayed-attributes`).then(
- // (arr) => new TrackedArray(arr)
- // )
- // );
-
constructor(data = {}) {
for (const key in data) {
this[key] = data[key];
}
}
- get indexPath() {
+ get path() {
return `indexes/${this.uid}`;
}
@@ -24,6 +18,45 @@ export default class Index {
return Boolean(!this.uid);
}
+ getSortableAttributes() {
+ return query(`${this.path}/settings/sortable-attributes`);
+ }
+
+ getStats() {
+ return query(`${this.path}/stats`);
+ }
+
+ // getDocuments(searchParams) {
+ // return query(`${this.path}/documents`, {
+ // body: searchParams,
+ // });
+ // }
+
+ getDocument(uid) {
+ return query(`${this.path}/documents/${uid}`).then(
+ (result) => new Document(this, result)
+ );
+ }
+
+ search(q, options = {}) {
+ options.q = q;
+
+ return query(`${this.path}/search`, {
+ method: 'POST',
+ body: JSON.stringify(options),
+ });
+ }
+
+ save(data) {
+ const path = this.isNew ? 'indexes' : this.path;
+ const method = this.isNew ? 'POST' : 'PATCH';
+
+ return query(path, {
+ method: method,
+ body: JSON.stringify(data),
+ });
+ }
+
// get allAttributesAreDisplayed() {
// return (
// this.displayedAttributes.value &&
@@ -33,73 +66,53 @@ export default class Index {
// }
// getDisplayedAttributes() {
- // return query(`${this.indexPath}/settings/displayed-attributes`);
+ // return query(`${this.path}/settings/displayed-attributes`);
// }
// updateDisplayedAttributes(value) {
- // return query(`${this.indexPath}/settings/displayed-attributes`, {
+ // return query(`${this.path}/settings/displayed-attributes`, {
// method: 'POST',
// body: JSON.stringify(value),
// });
// }
// resetDisplayedAttributes() {
- // return query(`${this.indexPath}/settings/displayed-attributes`, {
+ // return query(`${this.path}/settings/displayed-attributes`, {
// method: 'DELETE',
// });
// }
// getSearchableAttributes() {
- // return query(`${this.indexPath}/settings/searchable-attributes`);
+ // return query(`${this.path}/settings/searchable-attributes`);
// }
// updateSearchableAttributes(value) {
- // return query(`${this.indexPath}/settings/searchable-attributes`, {
+ // return query(`${this.path}/settings/searchable-attributes`, {
// method: 'POST',
// body: JSON.stringify(value),
// });
// }
// resetSearchableAttributes() {
- // return query(`${this.indexPath}/settings/searchable-attributes`, {
+ // return query(`${this.path}/settings/searchable-attributes`, {
// method: 'DELETE',
// });
// }
- getSortableAttributes() {
- return query(`${this.indexPath}/settings/sortable-attributes`);
- }
-
- getStats() {
- return query(`${this.indexPath}/stats`);
- }
-
- // getSettings() {
- // return query(`${this.indexPath}/settings`);
- // }
-
- search(q, options = {}) {
- options.q = q;
-
- return query(`${this.indexPath}/search`, {
- method: 'POST',
- body: JSON.stringify(options),
- });
- }
-
// get fields() {
// return this.stats.value
// ? Object.keys(this.stats.value.fieldDistribution)
// : [];
// }
- save(data) {
- const path = this.isNew ? 'indexes' : this.indexPath;
- const method = this.isNew ? 'POST' : 'PATCH';
+ // getSettings() {
+ // return query(`${this.path}/settings`);
+ // }
- return query(path, {
- method: method,
- body: JSON.stringify(data),
- });
- }
+ // stats = trackedFunction(this, () => query(`${this.path}/stats`));
+ // displayedAttributes = trackedFunction(this, () =>
+ // query(`${this.path}/settings/displayed-attributes`).then(
+ // (arr) => new TrackedArray(arr)
+ // )
+ // );
}
diff --git a/app/router.js b/app/router.js
index 2ad6368..000b966 100644
--- a/app/router.js
+++ b/app/router.js
@@ -13,7 +13,9 @@ Router.map(function () {
this.route('settings');
this.route('info');
this.route('edit');
- this.route('documents');
+ this.route('documents', function () {
+ this.route('document', { path: '/:uid' });
+ });
});
this.route('new');
});
diff --git a/app/routes/admin/indexes/item/documents.js b/app/routes/admin/indexes/item/documents.js
index 72d85e1..abd83c2 100644
--- a/app/routes/admin/indexes/item/documents.js
+++ b/app/routes/admin/indexes/item/documents.js
@@ -1,45 +1,3 @@
import Route from '@ember/routing/route';
-import { hash } from 'rsvp';
-export default class AdminIndexesItemDocumentsRoute extends Route {
- queryParams = {
- q: {
- refreshModel: true,
- },
- limit: {
- refreshModel: true,
- },
- page: {
- refreshModel: true,
- },
- sort: {
- refreshModel: true,
- },
- };
-
- async model({ q, page, limit, sort }) {
- const offset = limit * --page;
- const index = this.modelFor('admin.indexes.item');
- const options = { offset, limit };
-
- if (sort) {
- options.sort = [sort];
- }
-
- return hash({
- index,
- data: index.search(q, options),
- sortableAttributes: index.getSortableAttributes(),
- stats: index.getStats(),
- });
- }
-
- resetController(controller, isExiting) {
- if (isExiting) {
- controller.q = null;
- controller.page = 1;
- }
-
- window.scrollTo(0, 0);
- }
-}
+export default class AdminIndexesItemDocumentsRoute extends Route {}
diff --git a/app/routes/admin/indexes/item/documents/document.js b/app/routes/admin/indexes/item/documents/document.js
new file mode 100644
index 0000000..d3688e0
--- /dev/null
+++ b/app/routes/admin/indexes/item/documents/document.js
@@ -0,0 +1,13 @@
+import Route from '@ember/routing/route';
+import { hash } from 'rsvp';
+
+export default class AdminIndexesItemDocumentsDocumentRoute extends Route {
+ model({ uid }) {
+ const index = this.modelFor('admin.indexes.item');
+
+ return hash({
+ index,
+ document: index.getDocument(uid),
+ });
+ }
+}
diff --git a/app/routes/admin/indexes/item/documents/index.js b/app/routes/admin/indexes/item/documents/index.js
new file mode 100644
index 0000000..650d369
--- /dev/null
+++ b/app/routes/admin/indexes/item/documents/index.js
@@ -0,0 +1,45 @@
+import Route from '@ember/routing/route';
+import { hash } from 'rsvp';
+
+export default class AdminIndexesItemDocumentsIndexRoute extends Route {
+ queryParams = {
+ q: {
+ refreshModel: true,
+ },
+ limit: {
+ refreshModel: true,
+ },
+ page: {
+ refreshModel: true,
+ },
+ sort: {
+ refreshModel: true,
+ },
+ };
+
+ async model({ q, page, limit, sort }) {
+ const offset = limit * --page;
+ const index = this.modelFor('admin.indexes.item');
+ const options = { offset, limit };
+
+ if (sort) {
+ options.sort = [sort];
+ }
+
+ return hash({
+ index,
+ data: index.search(q, options),
+ sortableAttributes: index.getSortableAttributes(),
+ stats: index.getStats(),
+ });
+ }
+
+ resetController(controller, isExiting) {
+ if (isExiting) {
+ controller.q = null;
+ controller.page = 1;
+ }
+
+ window.scrollTo(0, 0);
+ }
+}
diff --git a/app/templates/admin/indexes/item/documents.hbs b/app/templates/admin/indexes/item/documents.hbs
index cdce521..c24cd68 100644
--- a/app/templates/admin/indexes/item/documents.hbs
+++ b/app/templates/admin/indexes/item/documents.hbs
@@ -1,59 +1 @@
-