@operato/attachment 1.0.0-beta.9 → 1.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.
@@ -2,19 +2,19 @@ import '@operato/data-grist'
2
2
  import '@operato/input/ox-input-file.js'
3
3
 
4
4
  import gql from 'graphql-tag'
5
- import i18next from 'i18next'
6
- import { css, html, LitElement, PropertyValues } from 'lit'
5
+ import { css, html, LitElement } from 'lit'
7
6
  import { customElement, property, query } from 'lit/decorators.js'
8
7
 
9
8
  import {
10
9
  ColumnConfig,
11
10
  DataGrist,
11
+ FetchOption,
12
12
  FieldRenderer,
13
13
  FiltersForm,
14
+ FilterValue,
14
15
  GristData,
15
16
  GristRecord,
16
17
  PaginationConfig,
17
- QueryFilter,
18
18
  SortersConfig
19
19
  } from '@operato/data-grist'
20
20
  import { buildArgs, client } from '@operato/graphql'
@@ -120,7 +120,6 @@ export class OxAttachmentList extends LitElement {
120
120
  `
121
121
  ]
122
122
 
123
- @property({ type: Array }) categories: any[] = ['audio', 'video', 'image', 'text', 'application']
124
123
  @property({ type: String }) category: string = ''
125
124
  @property({ type: Boolean }) creatable: boolean = false
126
125
 
@@ -132,25 +131,8 @@ export class OxAttachmentList extends LitElement {
132
131
  return html`
133
132
  <ox-grist .config=${this.gristConfig} .mode=${'CARD'} auto-fetch .fetchHandler=${this.fetchHandler.bind(this)}>
134
133
  <div slot="headroom" id="headroom">
135
-
136
134
  <div id="filters">
137
- <ox-filters-form
138
- slot="headroom"
139
- @change=${(e: Event) => this.grist.fetch(true)}
140
- ></ox-filters-form>
141
-
142
- <select
143
- @change=${(e: Event) => {
144
- this.category = (e.currentTarget as HTMLInputElement)?.value
145
- this.requestUpdate()
146
- }}
147
- >
148
- <option value="">${i18next.t('text.please choose a category')}</option>
149
- ${this.categories.map(
150
- category =>
151
- html` <option value=${category} ?selected=${this.category == category}>${category}</option> `
152
- )}
153
- </select>
135
+ <ox-filters-form autofocus></ox-filters-form>
154
136
  </div>
155
137
 
156
138
  <ox-input-file
@@ -159,13 +141,13 @@ export class OxAttachmentList extends LitElement {
159
141
  hide-filelist
160
142
  @change=${this.onCreateAttachment.bind(this)}
161
143
  ></ox-input-file>
144
+ </div>
162
145
  </ox-grist>
163
146
  `
164
147
  }
165
148
 
166
- async fetchHandler({ page, limit, sorters = [] }: { page: number; limit: number; sorters: SortersConfig }) {
167
- const filters: QueryFilter[] = await this.filtersForm.getQueryFilters()
168
- const { items: records, total } = await this.getAttachments({ page, limit, filters, sortings: sorters })
149
+ async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) {
150
+ const { items: records, total } = await this.getAttachments({ page, limit, filters, sortings })
169
151
 
170
152
  return {
171
153
  total,
@@ -306,6 +288,19 @@ export class OxAttachmentList extends LitElement {
306
288
  }
307
289
  }
308
290
  },
291
+ {
292
+ type: 'select',
293
+ name: 'category',
294
+ header: 'category',
295
+ record: {
296
+ options: ['', 'audio', 'video', 'image', 'text', 'application'],
297
+ editable: false
298
+ },
299
+ hidden: true,
300
+ filter: {
301
+ value: this.category
302
+ }
303
+ },
309
304
  {
310
305
  type: 'image',
311
306
  name: 'thumbnail',
@@ -387,12 +382,6 @@ export class OxAttachmentList extends LitElement {
387
382
  this.refreshAttachments()
388
383
  }
389
384
 
390
- updated(changes: PropertyValues<this>) {
391
- if (changes.has('category')) {
392
- this.refreshAttachments()
393
- }
394
- }
395
-
396
385
  onClickSelect(attachment: any) {
397
386
  this.dispatchEvent(
398
387
  new CustomEvent('attachment-selected', {
@@ -427,19 +416,12 @@ export class OxAttachmentList extends LitElement {
427
416
  limit = 30,
428
417
  filters = [],
429
418
  sortings = []
430
- }: { page?: number; limit?: number; filters?: QueryFilter[]; sortings?: SortersConfig } = {}) {
419
+ }: { page?: number; limit?: number; filters?: FilterValue[]; sortings?: SortersConfig } = {}) {
431
420
  var pagination: PaginationConfig = {
432
421
  limit,
433
422
  page
434
423
  }
435
424
 
436
- if (this.category)
437
- filters.push({
438
- name: 'category',
439
- operator: 'eq',
440
- value: this.category
441
- })
442
-
443
425
  var params = {
444
426
  filters,
445
427
  sortings,
@@ -1,14 +1,15 @@
1
1
  import './ox-attachment-selector'
2
2
 
3
- import { OxPropertyEditor } from '@operato/property-editor'
4
- import { customElement } from 'lit/decorators.js'
5
3
  import { html } from 'lit'
4
+ import { customElement } from 'lit/decorators.js'
5
+
6
+ import { OxPropertyEditor, PropertySpec } from '@operato/property-editor'
6
7
 
7
8
  @customElement('ox-property-editor-attachment-selector')
8
9
  class OxPropertyEditorAttachmentSelector extends OxPropertyEditor {
9
- editorTemplate() {
10
+ editorTemplate(value: any, spec: PropertySpec) {
10
11
  return html`
11
- <ox-attachment-selector id="editor" .value=${this.value} .properties=${this.property}></ox-attachment-selector>
12
+ <ox-attachment-selector id="editor" .value=${value} .properties=${spec.property}></ox-attachment-selector>
12
13
  `
13
14
  }
14
15
  }
@@ -1,18 +1,19 @@
1
1
  import './ox-attachment-selector'
2
2
 
3
- import { OxPropertyEditor } from '@operato/property-editor'
4
- import { customElement } from 'lit/decorators.js'
5
3
  import { html } from 'lit'
4
+ import { customElement } from 'lit/decorators.js'
5
+
6
+ import { OxPropertyEditor, PropertySpec } from '@operato/property-editor'
6
7
 
7
8
  @customElement('ox-property-editor-image-selector')
8
9
  class OxPropertyEditorImageSelector extends OxPropertyEditor {
9
- editorTemplate() {
10
+ editorTemplate(value: any, spec: PropertySpec) {
10
11
  return html`
11
12
  <ox-attachment-selector
12
13
  id="editor"
13
- .value=${this.value}
14
+ .value=${value}
14
15
  .properties=${{
15
- ...this.property,
16
+ ...spec.property,
16
17
  category: 'image'
17
18
  }}
18
19
  ></ox-attachment-selector>