Add search button

This commit is contained in:
Stanislav Romanov 2022-10-22 17:56:53 +03:00
parent 67b11e6226
commit 77761f5cf1
6 changed files with 63 additions and 14 deletions

View file

@ -30,6 +30,7 @@ export default class ButtonComponent extends Component {
disabled={{this.disabled}} disabled={{this.disabled}}
type={{this.type}} type={{this.type}}
class="inline-flex items-center justify-center min-w-min whitespace-nowrap class="inline-flex items-center justify-center min-w-min whitespace-nowrap
disabled:opacity-75 disabled:cursor-not-allowed
{{get sizes this.size}} {{get sizes this.size}}
{{get styles this.style}} {{get styles this.style}}
" "

View file

@ -1,7 +1,7 @@
import Component from '@glimmer/component'; import Component from '@glimmer/component';
import { action } from '@ember/object'; import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking'; import { tracked } from '@glimmer/tracking';
import ActionInvoker from '../lib/action-invoker'; import ActionInvoker from 'meiliadmin/lib/action-invoker';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
export default class FormIndexSettingComponent extends Component { export default class FormIndexSettingComponent extends Component {

View file

@ -33,6 +33,8 @@ function getModel(value, language, uri, schema) {
languages.json.jsonDefaults.setDiagnosticsOptions({ languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true, validate: true,
schemas: [schema], schemas: [schema],
schemaRequest: 'error',
schemaValidation: 'error',
}); });
} }
} }
@ -109,9 +111,9 @@ export default class MonacoEditorComponent extends Component {
}); });
} }
// Autoresize height of element
const minHeight = this.args.minHeight ?? 160; const minHeight = this.args.minHeight ?? 160;
const maxHeight = this.args.maxHeight ?? 420; const maxHeight = this.args.maxHeight ?? 420;
// Autoresize height of element
const onDidContentSizeChangeHandler = this.editor.onDidContentSizeChange( const onDidContentSizeChangeHandler = this.editor.onDidContentSizeChange(
() => { () => {
const contentHeight = Math.min( const contentHeight = Math.min(
@ -125,13 +127,33 @@ export default class MonacoEditorComponent extends Component {
); );
registerDestructor(this, onDidContentSizeChangeHandler.dispose); registerDestructor(this, onDidContentSizeChangeHandler.dispose);
// Validation // onDidChangeModelContent
const onDidChangeMarkersHandler = editor.onDidChangeMarkers(() => { if (this.args.onDidChangeModelContent) {
this.args.onDidValidation?.( const onDidChangeModelContent = this.editor.onDidChangeModelContent(
editor.getModelMarkers().map((item) => item.message) () => {
this.args.onDidChangeModelContent(
this.editor.getValue(),
this.editor
);
}
); );
}); registerDestructor(this, onDidChangeModelContent.dispose);
registerDestructor(this, onDidChangeMarkersHandler.dispose); }
// Validation
if (this.args.onDidValidation) {
const onDidChangeMarkersHandler = editor.onDidChangeMarkers(() => {
const model = this.editor.getModel();
this.args.onDidValidation(
editor
.getModelMarkers({ resource: model.uri })
.map((item) => item.message),
this.editor
);
});
registerDestructor(this, onDidChangeMarkersHandler.dispose);
}
} }
@action @action
@ -155,7 +177,7 @@ export default class MonacoEditorComponent extends Component {
@action @action
invokeSendValue() { invokeSendValue() {
this.args.sendValue?.(this.editor.getValue()); this.args.sendValue?.(this.editor.getValue(), this.editor);
} }
willDestroy() { willDestroy() {

View file

@ -3,6 +3,7 @@ import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking'; import { tracked } from '@glimmer/tracking';
import { Magnify, Table, /* MapOutline, */ CodeJson } from 'ember-mdi'; import { Magnify, Table, /* MapOutline, */ CodeJson } from 'ember-mdi';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import ActionInvoker from 'meiliadmin/lib/action-invoker';
export default class AdminIndexesItemDocumentsIndexController extends Controller { export default class AdminIndexesItemDocumentsIndexController extends Controller {
@service router; @service router;
@ -16,6 +17,7 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller
@tracked hiddenFields = []; @tracked hiddenFields = [];
@tracked dataView = 'table'; @tracked dataView = 'table';
@tracked isAdvancedSearch = false; @tracked isAdvancedSearch = false;
@tracked errors;
queryParams = ['q', 'limit', 'offset', 'sort', 'attributesToRetrieve']; queryParams = ['q', 'limit', 'offset', 'sort', 'attributesToRetrieve'];
@ -27,7 +29,13 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller
json: CodeJson, json: CodeJson,
}; };
get search() { constructor() {
super(...arguments);
this.invoker = new ActionInvoker();
}
get searchObject() {
return this.queryParams.reduce((properties, item) => { return this.queryParams.reduce((properties, item) => {
properties[item] = this[item]; properties[item] = this[item];
@ -119,4 +127,13 @@ export default class AdminIndexesItemDocumentsIndexController extends Controller
sortAttibutes(items) { sortAttibutes(items) {
this.attributesToRetrieve = items.filter(this.isItemChecked); this.attributesToRetrieve = items.filter(this.isItemChecked);
} }
@action
search(value) {
const obj = JSON.parse(value);
this.queryParams.forEach((item) => {
this[item] = obj[item];
});
}
} }

View file

@ -22,16 +22,23 @@
{{#if this.isAdvancedSearch}} {{#if this.isAdvancedSearch}}
<Form::Element @errors={{this.errors}}> <Form::Element @errors={{this.errors}}>
<MonacoEditor <MonacoEditor
@value={{json-stringify this.search}} @value={{json-stringify this.searchObject}}
@language='json' @language='json'
@uri={{@model.searchSchema.uri}} @uri={{@model.searchSchema.uri}}
@schema={{@model.searchSchema}} @schema={{@model.searchSchema}}
{{!-- @sendValue={{this.save}} --}} @sendValue={{this.search}}
{{!-- @invoker={{this.invoker}} --}} @invoker={{this.invoker}}
@onDidValidation={{set this 'errors'}} @onDidValidation={{set this 'errors'}}
class='mb-4'
/> />
</Form::Element> </Form::Element>
<Button
@text='Search'
@style='primary'
@onClick={{fn this.invoker.invoke 'invokeSendValue'}}
class='mb-4'
disabled={{or this.isValidating this.errors.length}}
/>
{{else}} {{else}}
<div class='sm:flex sm:flex-nowrap'> <div class='sm:flex sm:flex-nowrap'>
{{! q }} {{! q }}

View file

@ -17,3 +17,5 @@ class Property {
export const type = (type) => { export const type = (type) => {
return new Property(type); return new Property(type);
}; };
export default { type };