Add resort fileds in document table

This commit is contained in:
Stanislav Romanov 2022-09-10 19:07:58 +03:00
parent f920f7969f
commit 09649c43ba
6 changed files with 58 additions and 152 deletions

View file

@ -0,0 +1 @@
export { DragHorizontal as default } from 'ember-mdi';

View file

@ -10,6 +10,7 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller
@tracked dataView = 'table';
@tracked sort;
@tracked hiddenFields = [];
@tracked attributes;
queryParams = ['q', 'page', 'limit', 'sort'];
@ -21,17 +22,6 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller
map: MapOutline,
};
get attributes() {
if (
this.model.displayedAttributes.length > 1 &&
this.model.displayedAttributes[0] !== '*'
) {
return this.model.displayedAttributes;
} else {
return Object.keys(this.model.stats.fieldDistribution);
}
}
get fromHits() {
return 1 + this.model.data.offset;
}
@ -50,26 +40,6 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller
return result;
}
// 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
toggleHiddenField(name) {
if (this.hiddenFields.includes(name)) {

View file

@ -35,6 +35,19 @@ export default class AdminIndexesItemDocumentsIndexRoute extends Route {
});
}
setupController(controller, model) {
super.setupController(controller, model);
if (
model.displayedAttributes.length > 1 &&
model.displayedAttributes[0] !== '*'
) {
controller.attributes = model.displayedAttributes;
} else {
controller.attributes = Object.keys(model.stats.fieldDistribution);
}
}
resetController(controller, isExiting) {
if (isExiting) {
controller.q = null;

View file

@ -15,7 +15,7 @@
/>
{{#if this.sortValues.length}}
<div class='inline relative mb-4 sm:ml-4'>
<div class='relative mb-4 sm:ml-4'>
<Listbox @value={{this.sort}} @onChange={{set this 'sort'}} as |listbox|>
<listbox.Button
class='inline-flex items-center justify-center min-w-min w-24 px-3 py-2 border rounded cursor-pointer'
@ -37,7 +37,7 @@
</options.Option>
{{/each}}
<Divider class="my-1"/>
<Divider class='my-1' />
<options.Option @value={{null}} class='outline-none'>
<div
@ -51,20 +51,27 @@
</div>
{{/if}}
<div class='inline relative mb-4 sm:ml-4'>
<div class='relative mb-4 sm:ml-4'>
<Menu as |menu|>
<menu.Button as |menuButton|>
<Button @style='link' @onClick={{menuButton.toggleMenu}} class='w-auto'>
<Icons::DotsHorizontal />
</Button>
</menu.Button>
<menu.Items
class='absolute z-dropdown right-0 w-28 min-w-min mt-2 py-1 origin-top-right bg-base-7 border rounded shadow-sm outline-none'
{{sortable-group onChange=(set this 'attributes')}}
>
{{#each this.attributes as |item|}}
<div
class='flex items-center px-4 py-2 text-sm hover:bg-base-6 hover:text-base-1 cursor-pointer'
{{sortable-item model=item}}
>
<Icons::DragHorizontal
{{sortable-handle}}
class='mr-2 cursor-move'
/>
<Form::Checkbox
@checked={{not (includes item this.hiddenFields)}}
@label={{namelize item}}
@ -98,27 +105,8 @@
class='w-full'
as |Column data|
>
{{#if (not (includes @model.index.primaryKey this.hiddenFields))}}
<Column
@name={{capitalize @model.index.primaryKey}}
@prop={{@model.index.primaryKey}}
@sortable={{includes @model.index.primaryKey @model.sortableAttributes}}
>
<LinkTo
@route='admin.indexes.item.documents.document'
@model={{get data @model.index.primaryKey}}
>
{{get data @model.index.primaryKey}}
</LinkTo>
</Column>
{{/if}}
{{#each this.attributes as |field|}}
{{#if
(and
(not-eq field @model.index.primaryKey)
(not (includes field this.hiddenFields))
)
}}
{{#if (not (includes field this.hiddenFields))}}
<Column
@name={{capitalize field}}
@prop={{field}}

View file

@ -76,7 +76,7 @@
"ember-resources": "^4.7.1",
"ember-set-helper": "^2.0.1",
"ember-simple-auth": "^4.2.2",
"ember-sortable": "^3.0.1",
"ember-sortable": "^4.0.0",
"ember-source": "~4.6.0",
"ember-template-imports": "^3.1.1",
"ember-template-lint": "^4.10.1",

128
yarn.lock
View file

@ -100,7 +100,7 @@
browserslist "^4.20.2"
semver "^6.3.0"
"@babel/helper-create-class-features-plugin@^7.18.6", "@babel/helper-create-class-features-plugin@^7.18.9", "@babel/helper-create-class-features-plugin@^7.5.5", "@babel/helper-create-class-features-plugin@^7.8.3":
"@babel/helper-create-class-features-plugin@^7.18.6", "@babel/helper-create-class-features-plugin@^7.18.9", "@babel/helper-create-class-features-plugin@^7.5.5":
version "7.18.13"
resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.18.13.tgz#63e771187bd06d234f95fdf8bd5f8b6429de6298"
integrity sha512-hDvXp+QYxSRL+23mpAlSGxHMDyIGChm0/AwTfTAAK5Ufe40nCsyNdaYCGuK91phn/fVu9kqayImRDkvNAgdrsA==
@ -393,7 +393,7 @@
"@babel/helper-plugin-utils" "^7.18.9"
"@babel/plugin-syntax-logical-assignment-operators" "^7.10.4"
"@babel/plugin-proposal-nullish-coalescing-operator@^7.12.1", "@babel/plugin-proposal-nullish-coalescing-operator@^7.14.5", "@babel/plugin-proposal-nullish-coalescing-operator@^7.18.6", "@babel/plugin-proposal-nullish-coalescing-operator@^7.4.4":
"@babel/plugin-proposal-nullish-coalescing-operator@^7.12.1", "@babel/plugin-proposal-nullish-coalescing-operator@^7.14.5", "@babel/plugin-proposal-nullish-coalescing-operator@^7.18.6":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.18.6.tgz#fdd940a99a740e577d6c753ab6fbb43fdb9467e1"
integrity sha512-wQxQzxYeJqHcfppzBDnm1yAY0jSRkUXR2z8RePZYrKwMKgMlE8+Z6LUno+bd6LvbGh8Gltvy74+9pIYkr+XkKA==
@ -428,7 +428,7 @@
"@babel/helper-plugin-utils" "^7.18.6"
"@babel/plugin-syntax-optional-catch-binding" "^7.8.3"
"@babel/plugin-proposal-optional-chaining@^7.12.7", "@babel/plugin-proposal-optional-chaining@^7.14.5", "@babel/plugin-proposal-optional-chaining@^7.18.9", "@babel/plugin-proposal-optional-chaining@^7.6.0":
"@babel/plugin-proposal-optional-chaining@^7.12.7", "@babel/plugin-proposal-optional-chaining@^7.14.5", "@babel/plugin-proposal-optional-chaining@^7.18.9":
version "7.18.9"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.18.9.tgz#e8e8fe0723f2563960e4bf5e9690933691915993"
integrity sha512-v5nwt4IqBXihxGsW2QmCWMDS3B3bzGIk/EQVZz2ei7f3NJl8NzAJVvUmpDW5q1CRNY+Beb/k58UAH1Km1N411w==
@ -589,7 +589,7 @@
dependencies:
"@babel/helper-plugin-utils" "^7.14.5"
"@babel/plugin-syntax-typescript@^7.18.6", "@babel/plugin-syntax-typescript@^7.2.0", "@babel/plugin-syntax-typescript@^7.8.3":
"@babel/plugin-syntax-typescript@^7.18.6", "@babel/plugin-syntax-typescript@^7.2.0":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.18.6.tgz#1c09cd25795c7c2b8a4ba9ae49394576d4133285"
integrity sha512-mAWAuq4rvOepWCBid55JuRNvpTNf2UGVgoz4JV0fXEKolsVZDzsa4NqCef758WZJj/GDu0gVGItjKFiClTAmZA==
@ -871,15 +871,6 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-syntax-typescript" "^7.2.0"
"@babel/plugin-transform-typescript@~7.8.0":
version "7.8.7"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.8.7.tgz#48bccff331108a7b3a28c3a4adc89e036dc3efda"
integrity sha512-7O0UsPQVNKqpHeHLpfvOG4uXmlw+MOxYvUv6Otc9uH5SYMIxvF6eBdjkWvC3f9G+VXe0RsNExyAQBeTRug/wqQ==
dependencies:
"@babel/helper-create-class-features-plugin" "^7.8.3"
"@babel/helper-plugin-utils" "^7.8.3"
"@babel/plugin-syntax-typescript" "^7.8.3"
"@babel/plugin-transform-unicode-escapes@^7.18.10":
version "7.18.10"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.18.10.tgz#1ecfb0eda83d09bbcb77c09970c2dd55832aa246"
@ -1114,18 +1105,7 @@
ember-cli-htmlbars "^5.7.1"
ember-destroyable-polyfill "^2.0.3"
"@ember/test-waiters@^2.4.4":
version "2.4.5"
resolved "https://registry.yarnpkg.com/@ember/test-waiters/-/test-waiters-2.4.5.tgz#6e8e34d1bc46a9b0cc22cb11cc5936046e926031"
integrity sha512-833JvHtHdEfBfKXgvmw+6oziFOpVfD4NQrc04Ztj59A11K9FPNfZ3P8YydL7LFTtdd7UfJ/cYCLAm+OwUxbotQ==
dependencies:
calculate-cache-key-for-tree "^2.0.0"
ember-cli-babel "^7.26.6"
ember-cli-typescript "^4.1.0"
ember-cli-version-checker "^5.1.2"
semver "^7.3.5"
"@ember/test-waiters@^3.0.0":
"@ember/test-waiters@^3.0.0", "@ember/test-waiters@^3.0.1":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@ember/test-waiters/-/test-waiters-3.0.2.tgz#5b950c580a1891ed1d4ee64f9c6bacf49a15ea6f"
integrity sha512-H8Q3Xy9rlqhDKnQpwt2pzAYDouww4TZIGSI1pZJhM7mQIGufQKuB0ijzn/yugA6Z+bNdjYp1HioP8Y4hn2zazQ==
@ -1238,7 +1218,7 @@
resolved "https://registry.yarnpkg.com/@embroider/hbs-loader/-/hbs-loader-1.8.3.tgz#94c37dfacbe14c0133b6b958aa5d4171463a9b0f"
integrity sha512-Lkl14BnOGHNeBJSbGbxdmakmyIzeHdGO7820gCBMTG+klC8F1JqJbr7p7DfNEc/ci/2E8UirDx3OlnYV/yWOXA==
"@embroider/macros@1.8.3", "@embroider/macros@^1.0.0", "@embroider/macros@^1.2.0", "@embroider/macros@^1.6.0":
"@embroider/macros@1.8.3", "@embroider/macros@^0.50.0 || ^1.0.0", "@embroider/macros@^1.0.0", "@embroider/macros@^1.2.0", "@embroider/macros@^1.6.0":
version "1.8.3"
resolved "https://registry.yarnpkg.com/@embroider/macros/-/macros-1.8.3.tgz#2f0961ab8871f6ad819630208031d705b357757e"
integrity sha512-gnIOfTL/pUkoD6oI7JyWOqXlVIUgZM+CnbH10/YNtZr2K0hij9eZQMdgjOZZVgN0rKOFw9dIREqc1ygrJHRYQA==
@ -4001,14 +3981,6 @@ broccoli-debug@^0.6.4, broccoli-debug@^0.6.5:
symlink-or-copy "^1.1.8"
tree-sync "^1.2.2"
broccoli-file-creator@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/broccoli-file-creator/-/broccoli-file-creator-1.2.0.tgz#27f1b25b1b00e7bb7bf3d5d7abed5f4d5388df4d"
integrity sha512-l9zthHg6bAtnOfRr/ieZ1srRQEsufMZID7xGYRW3aBDv3u/3Eux+Iawl10tAGYE5pL9YB4n5X4vxkp6iNOoZ9g==
dependencies:
broccoli-plugin "^1.1.0"
mkdirp "^0.5.1"
broccoli-file-creator@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/broccoli-file-creator/-/broccoli-file-creator-2.1.1.tgz#7351dd2496c762cfce7736ce9b49e3fce0c7b7db"
@ -5813,7 +5785,7 @@ ember-cli-get-component-path-option@^1.0.0:
resolved "https://registry.yarnpkg.com/ember-cli-get-component-path-option/-/ember-cli-get-component-path-option-1.0.0.tgz#0d7b595559e2f9050abed804f1d8eff1b08bc771"
integrity sha512-k47TDwcJ2zPideBCZE8sCiShSxQSpebY2BHcX2DdipMmBox5gsfyVrbKJWIHeSTTKyEUgmBIvQkqTOozEziCZA==
ember-cli-htmlbars@^5.0.0, ember-cli-htmlbars@^5.7.1:
ember-cli-htmlbars@^5.7.1:
version "5.7.2"
resolved "https://registry.yarnpkg.com/ember-cli-htmlbars/-/ember-cli-htmlbars-5.7.2.tgz#e0cd2fb3c20d85fe4c3e228e6f0590ee1c645ba8"
integrity sha512-Uj6R+3TtBV5RZoJY14oZn/sNPnc+UgmC8nb5rI4P3fR/gYoyTFIZSXiIM7zl++IpMoIrocxOrgt+mhonKphgGg==
@ -5984,26 +5956,6 @@ ember-cli-typescript@^2.0.2:
stagehand "^1.0.0"
walk-sync "^1.0.0"
ember-cli-typescript@^3.1.3:
version "3.1.4"
resolved "https://registry.yarnpkg.com/ember-cli-typescript/-/ember-cli-typescript-3.1.4.tgz#21d6ccd670d1f2e34c9cce68c6e32c442f46806b"
integrity sha512-HJ73kL45OGRmIkPhBNFt31I1SGUvdZND+LCH21+qpq3pPlFpJG8GORyXpP+2ze8PbnITNLzwe5AwUrpyuRswdQ==
dependencies:
"@babel/plugin-proposal-nullish-coalescing-operator" "^7.4.4"
"@babel/plugin-proposal-optional-chaining" "^7.6.0"
"@babel/plugin-transform-typescript" "~7.8.0"
ansi-to-html "^0.6.6"
broccoli-stew "^3.0.0"
debug "^4.0.0"
ember-cli-babel-plugin-helpers "^1.0.0"
execa "^3.0.0"
fs-extra "^8.0.0"
resolve "^1.5.0"
rsvp "^4.8.1"
semver "^6.3.0"
stagehand "^1.0.0"
walk-sync "^2.0.0"
ember-cli-typescript@^4.1.0, ember-cli-typescript@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/ember-cli-typescript/-/ember-cli-typescript-4.2.1.tgz#54d08fc90318cc986f3ea562f93ce58a6cc4c24d"
@ -6020,7 +5972,7 @@ ember-cli-typescript@^4.1.0, ember-cli-typescript@^4.2.1:
stagehand "^1.0.0"
walk-sync "^2.2.0"
ember-cli-typescript@^5.1.0:
ember-cli-typescript@^5.0.0, ember-cli-typescript@^5.1.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/ember-cli-typescript/-/ember-cli-typescript-5.1.1.tgz#cf561026f3e7bd05312c1c212acffa1c30d5fa0c"
integrity sha512-DbzATYWY8nbXwSxXqtK8YlqGJTcyFyL+eg6IGCc2ur0AMnq/H+o6Z9np9eGoq1sI+HwX7vBkOVoD3k0WurAwXg==
@ -6168,7 +6120,7 @@ ember-cli@~4.6.0:
workerpool "^6.2.1"
yam "^1.0.0"
ember-compatibility-helpers@^1.1.2, ember-compatibility-helpers@^1.2.0, ember-compatibility-helpers@^1.2.1, ember-compatibility-helpers@^1.2.4:
ember-compatibility-helpers@^1.1.2, ember-compatibility-helpers@^1.2.0, ember-compatibility-helpers@^1.2.1, ember-compatibility-helpers@^1.2.5:
version "1.2.6"
resolved "https://registry.yarnpkg.com/ember-compatibility-helpers/-/ember-compatibility-helpers-1.2.6.tgz#603579ab2fb14be567ef944da3fc2d355f779cd8"
integrity sha512-2UBUa5SAuPg8/kRVaiOfTwlXdeVweal1zdNPibwItrhR0IvPrXpaqwJDlEZnWKEoB+h33V0JIfiWleSG6hGkkA==
@ -6256,13 +6208,13 @@ ember-fetch@^8.1.1:
node-fetch "^2.6.1"
whatwg-fetch "^3.6.2"
ember-get-config@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/ember-get-config/-/ember-get-config-0.3.0.tgz#a73a1a87b48d9dde4c66a0e52ed5260b8a48cfbd"
integrity sha512-0e2pKzwW5lBZ4oJnvu9qHOht4sP1MWz/m3hyz8kpSoMdrlZVf62LDKZ6qfKgy8drcv5YhCMYE6QV7MhnqlrzEQ==
ember-get-config@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ember-get-config/-/ember-get-config-2.1.1.tgz#bede76c25d95dbefab8d30064abf7aa00bc19235"
integrity sha512-uNmv1cPG/4qsac8oIf5txJ2FZ8p88LEpG4P3dNcjsJS98Y8hd0GPMFwVqpnzI78Lz7VYRGQWY4jnE4qm5R3j4g==
dependencies:
broccoli-file-creator "^1.1.1"
ember-cli-babel "^7.0.0"
"@embroider/macros" "^0.50.0 || ^1.0.0"
ember-cli-babel "^7.26.6"
"ember-getowner-polyfill@^1.1.0 || ^2.0.0":
version "2.2.0"
@ -6347,18 +6299,16 @@ ember-modifier@4.0.0-beta.1:
ember-cli-normalize-entity-name "^1.0.0"
ember-cli-string-utils "^1.1.0"
ember-modifier@^2.1.0:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ember-modifier/-/ember-modifier-2.1.2.tgz#62d18faedf972dcd9d34f90d5321fbc943d139b1"
integrity sha512-3Lsu1fV1sIGa66HOW07RZc6EHISwKt5VA5AUnFss2HX6OTfpxTJ2qvPctt2Yt0XPQXJ4G6BQasr/F35CX7UGJA==
ember-modifier@^3.2.0:
version "3.2.7"
resolved "https://registry.yarnpkg.com/ember-modifier/-/ember-modifier-3.2.7.tgz#f2d35b7c867cbfc549e1acd8d8903c5ecd02ea4b"
integrity sha512-ezcPQhH8jUfcJQbbHji4/ZG/h0yyj1jRDknfYue/ypQS8fM8LrGcCMo0rjDZLzL1Vd11InjNs3BD7BdxFlzGoA==
dependencies:
ember-cli-babel "^7.22.1"
ember-cli-babel "^7.26.6"
ember-cli-normalize-entity-name "^1.0.0"
ember-cli-string-utils "^1.1.0"
ember-cli-typescript "^3.1.3"
ember-compatibility-helpers "^1.2.4"
ember-destroyable-polyfill "^2.0.2"
ember-modifier-manager-polyfill "^1.2.0"
ember-cli-typescript "^5.0.0"
ember-compatibility-helpers "^1.2.5"
ember-modifier@^4.0.0-beta.1:
version "4.0.0-beta.1-unstable.a4fec35"
@ -6440,18 +6390,18 @@ ember-simple-auth@^4.2.2:
ember-cookies "^0.5.0"
silent-error "^1.0.0"
ember-sortable@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ember-sortable/-/ember-sortable-3.0.1.tgz#7858d2d4e029e36f86eb7af13f27b23943da1741"
integrity sha512-LFNAD3OkZ1bJ0n+iK1/pjOMBf/hR6ExqrJR7MBeZ8s4ZOVt+yei2LacEI3jSoWXPoQW+prQew4H2fYrTuk+kaA==
ember-sortable@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/ember-sortable/-/ember-sortable-4.0.0.tgz#32dec14110913d40840eb4defdf7bea082334a18"
integrity sha512-fRR7946IXwIt7SPMqRN2dJ3Gxaw6ioF/fzv/yzOPRBAaLMRRy3U8BGqCM0bNnE8IRuhRd63ox98Y0aFIkK43Hw==
dependencies:
"@ember/render-modifiers" "^1.0.2 || ^2.0.0"
"@ember/test-waiters" "^2.4.4"
ember-cli-babel "^7.26.6"
ember-cli-htmlbars "^5.0.0"
"@ember/test-waiters" "^3.0.1"
ember-cli-babel "^7.26.11"
ember-cli-htmlbars "^6.0.1"
ember-cli-version-checker "^5.1.2"
ember-get-config "^0.3.0"
ember-modifier "^2.1.0"
ember-get-config "^2.0.0"
ember-modifier "^3.2.0"
ember-test-selectors "^6.0.0"
ember-source-channel-url@^3.0.0:
@ -7079,22 +7029,6 @@ execa@^2.0.0:
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"
execa@^3.0.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-3.4.0.tgz#c08ed4550ef65d858fac269ffc8572446f37eb89"
integrity sha512-r9vdGQk4bmCuK1yKQu1KTwcT2zwfWdbdaXfCtAh+5nU/4fSX+JAb7vZGvI5naJrQlvONrEB20jeruESI69530g==
dependencies:
cross-spawn "^7.0.0"
get-stream "^5.0.0"
human-signals "^1.1.1"
is-stream "^2.0.0"
merge-stream "^2.0.0"
npm-run-path "^4.0.0"
onetime "^5.1.0"
p-finally "^2.0.0"
signal-exit "^3.0.2"
strip-final-newline "^2.0.0"
execa@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.1.0.tgz#4e5491ad1572f2f17a77d388c6c857135b22847a"