Add all index settings to form
This commit is contained in:
parent
cf50ec5698
commit
4816efb3ff
2 changed files with 19 additions and 247 deletions
|
|
@ -1,6 +1,4 @@
|
|||
import query from '../utils/query';
|
||||
// import { TrackedArray } from 'tracked-built-ins';
|
||||
// import { trackedFunction } from 'ember-resources/util/function';
|
||||
import Document from './document';
|
||||
import { dasherize } from '@ember/string';
|
||||
|
||||
|
|
@ -11,6 +9,22 @@ export default class Index {
|
|||
}
|
||||
}
|
||||
|
||||
get settingNames() {
|
||||
return [
|
||||
'displayedAttributes',
|
||||
'distinctAttribute',
|
||||
'faceting',
|
||||
'filterableAttributes',
|
||||
'pagination',
|
||||
'rankingRules',
|
||||
'searchableAttributes',
|
||||
'sortableAttributes',
|
||||
'stopWords',
|
||||
'synonyms',
|
||||
'typoTolerance',
|
||||
];
|
||||
}
|
||||
|
||||
get path() {
|
||||
return `indexes/${this.uid}`;
|
||||
}
|
||||
|
|
@ -83,72 +97,4 @@ export default class Index {
|
|||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
getDisplayedAttributes() {
|
||||
return query(`${this.path}/settings/displayed-attributes`);
|
||||
}
|
||||
|
||||
updateDisplayedAttributes(value) {
|
||||
return query(`${this.path}/settings/displayed-attributes`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(value),
|
||||
});
|
||||
}
|
||||
|
||||
resetDisplayedAttributes() {
|
||||
return query(`${this.path}/settings/displayed-attributes`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
getDistinctAttribute() {
|
||||
return query(`${this.path}/settings/distinct-attribute`);
|
||||
}
|
||||
|
||||
updateDistinctAttribute(value) {
|
||||
return query(`${this.path}/settings/distinct-attribute`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(value),
|
||||
});
|
||||
}
|
||||
|
||||
resetDistinctAttribute() {
|
||||
return query(`${this.path}/settings/distinct-attribute`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
// getSearchableAttributes() {
|
||||
// return query(`${this.path}/settings/searchable-attributes`);
|
||||
// }
|
||||
|
||||
// updateSearchableAttributes(value) {
|
||||
// return query(`${this.path}/settings/searchable-attributes`, {
|
||||
// method: 'POST',
|
||||
// body: JSON.stringify(value),
|
||||
// });
|
||||
// }
|
||||
|
||||
// resetSearchableAttributes() {
|
||||
// return query(`${this.path}/settings/searchable-attributes`, {
|
||||
// method: 'DELETE',
|
||||
// });
|
||||
// }
|
||||
|
||||
// get fields() {
|
||||
// return this.stats.value
|
||||
// ? Object.keys(this.stats.value.fieldDistribution)
|
||||
// : [];
|
||||
// }
|
||||
|
||||
// getSettings() {
|
||||
// return query(`${this.path}/settings`);
|
||||
// }
|
||||
|
||||
// stats = trackedFunction(this, () => query(`${this.path}/stats`));
|
||||
// displayedAttributes = trackedFunction(this, () =>
|
||||
// query(`${this.path}/settings/displayed-attributes`).then(
|
||||
// (arr) => new TrackedArray(arr)
|
||||
// )
|
||||
// );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,177 +1,3 @@
|
|||
<IndexSetting
|
||||
@name='displayedAttributes'
|
||||
@index={{@model}}
|
||||
/>
|
||||
|
||||
<IndexSetting
|
||||
@name='distinctAttribute'
|
||||
@index={{@model}}
|
||||
/>
|
||||
|
||||
{{!-- <label class="text-xl mb-2 block">
|
||||
Displayed attributes
|
||||
</label>
|
||||
<div class="mb-2">
|
||||
{{#each @model.index.fields as |item|}}
|
||||
{{#let
|
||||
(or
|
||||
(eq @model.displayedAttributes.firstObject '*')
|
||||
(includes item @model.displayedAttributes)
|
||||
) as |checked|
|
||||
}}
|
||||
<Badge
|
||||
@label={{item}}
|
||||
@icon={{if checked this.Check this.CircleMedium}}
|
||||
@style={{if checked 'success'}}
|
||||
class="cursor-pointer"
|
||||
{{on 'click' (fn this.setAttributeValue 'displayedAttributes' item)}}
|
||||
/>
|
||||
{{/let}}
|
||||
{{/each}}
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<Button
|
||||
@text="Update"
|
||||
@style="primary"
|
||||
@size="small"
|
||||
@onClick={{fn
|
||||
this.update
|
||||
'updateDisplayedAttributes'
|
||||
@model.displayedAttributes
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
@text="Reset"
|
||||
@size="small"
|
||||
@style="outline"
|
||||
@onClick={{fn this.reset 'resetDisplayedAttributes'}}
|
||||
/>
|
||||
</div>
|
||||
<label class="text-xl mb-2 block">
|
||||
Searchable attributes
|
||||
</label>
|
||||
<div class="mb-2">
|
||||
{{#each @model.index.fields as |item|}}
|
||||
{{#let
|
||||
(or
|
||||
(eq @model.searchableAttributes.firstObject '*')
|
||||
(includes item @model.searchableAttributes)
|
||||
) as |checked|
|
||||
}}
|
||||
<Badge
|
||||
@label={{item}}
|
||||
@icon={{if checked this.Check this.CircleMedium}}
|
||||
@style={{if checked 'success'}}
|
||||
class="cursor-pointer"
|
||||
{{on 'click' (fn this.setAttributeValue 'searchableAttributes' item)}}
|
||||
/>
|
||||
{{/let}}
|
||||
{{/each}}
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<Button
|
||||
@text="Update"
|
||||
@style="primary"
|
||||
@size="small"
|
||||
@onClick={{fn
|
||||
this.update
|
||||
'updateSearchableAttributes'
|
||||
@model.searchableAttributes
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
@text="Reset"
|
||||
@size="small"
|
||||
@style="outline"
|
||||
@onClick={{fn this.reset 'resetSearchableAttributes'}}
|
||||
/>
|
||||
</div> --}}
|
||||
{{!--
|
||||
<RoyalTable @data={{@model.attributes}} as |Row data|>
|
||||
<Row as |Column|>
|
||||
<Column @prop="name" />
|
||||
<Column @name="Displayed">
|
||||
<InputCheckbox
|
||||
@checked={{data.displayed}}
|
||||
@onChange={{set data 'displayed'}}
|
||||
/>
|
||||
</Column>
|
||||
<Column @name="Filterable">
|
||||
<InputCheckbox
|
||||
@checked={{data.filterable}}
|
||||
@onChange={{set data 'filterable'}}
|
||||
/>
|
||||
</Column>
|
||||
<Column @name="Searchable">
|
||||
<InputCheckbox
|
||||
@checked={{data.searchable}}
|
||||
@onChange={{set data 'searchable'}}
|
||||
/>
|
||||
</Column>
|
||||
<Column @name="Sortable">
|
||||
<InputCheckbox
|
||||
@checked={{data.sortable}}
|
||||
@onChange={{set data 'sortable'}}
|
||||
/>
|
||||
</Column>
|
||||
</Row>
|
||||
</RoyalTable>
|
||||
<InputSelect
|
||||
@label="Distinct attribute"
|
||||
@options={{keys @model.stats.fieldDistribution}}
|
||||
@selected={{@model.settings.distinctAttribute}}
|
||||
@onChange={{set @model.settings 'distinctAttribute'}}
|
||||
@allowClear={{true}} as |option|
|
||||
>
|
||||
{{option}}
|
||||
</InputSelect>
|
||||
<div class="mb-4">
|
||||
<label class="mb-2">
|
||||
Ranking rules
|
||||
</label>
|
||||
<div {{sortable-group onChange=this.reorderItems}}>
|
||||
{{#each @model.settings.rankingRules as |item|}}
|
||||
<div
|
||||
class="flex items-center px-4 py-2 mb-2 border max-w-md"
|
||||
{{sortable-item model=item}}
|
||||
>
|
||||
<Icons::DragVertical class="mr-2 -ml-2 cursor-move" />
|
||||
{{item}}
|
||||
<Icons::CloseThick
|
||||
@size="16"
|
||||
class="ml-auto cursor-pointer"
|
||||
{{on 'click' (fn this.removeRankingRule item)}}
|
||||
/>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{#if this.rankingRulesFields.length}}
|
||||
<InputSelect
|
||||
@options={{this.rankingRulesFields}}
|
||||
@onChange={{this.selectNewRankingRule}}
|
||||
@placeholder="Add field" as |option|
|
||||
>
|
||||
{{option}}
|
||||
</InputSelect>
|
||||
{{/if}}
|
||||
</div>
|
||||
<InputTextarea
|
||||
@label="Stop-words"
|
||||
@value={{json-stringify @model.settings.stopWords}}
|
||||
@onChange={{fn this.saveStrToJSON 'stopWords' (array)}}
|
||||
@helper="JSON format"
|
||||
/>
|
||||
<InputTextarea
|
||||
@label="Synonyms"
|
||||
@value={{json-stringify @model.settings.synonyms}}
|
||||
@onChange={{fn this.saveStrToJSON 'synonyms' this.emptyObj}}
|
||||
@helper="JSON format"
|
||||
/>
|
||||
<Button
|
||||
@text="Save"
|
||||
@pendingText="Saving"
|
||||
@fulfilledText="Done"
|
||||
@rejectedText="Error"
|
||||
@icon={{this.ContentSaveOutline}}
|
||||
@onClick={{this.save}}
|
||||
/> --}}
|
||||
{{#each @model.settingNames as |name|}}
|
||||
<IndexSetting @name={{name}} @index={{@model}} />
|
||||
{{/each}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue