@operato/attachment 1.0.0-beta.5 → 1.0.0-beta.50

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.
@@ -1,25 +1,25 @@
1
1
  import '@operato/data-grist'
2
2
  import '@operato/input/ox-input-file.js'
3
3
 
4
+ import gql from 'graphql-tag'
5
+ import { css, html, LitElement } from 'lit'
6
+ import { customElement, property, query } from 'lit/decorators.js'
7
+
4
8
  import {
5
9
  ColumnConfig,
6
10
  DataGrist,
11
+ FetchOption,
7
12
  FieldRenderer,
8
13
  FiltersForm,
14
+ FilterValue,
9
15
  GristData,
10
16
  GristRecord,
11
17
  PaginationConfig,
12
- QueryFilter,
13
18
  SortersConfig
14
19
  } from '@operato/data-grist'
15
- import { LitElement, PropertyValues, css, html } from 'lit'
16
- import { ScrollbarStyles, TooltipStyles } from '@operato/styles'
17
20
  import { buildArgs, client } from '@operato/graphql'
18
- import { customElement, property, query } from 'lit/decorators.js'
19
-
20
- import gql from 'graphql-tag'
21
- import i18next from 'i18next'
22
- import { sleep } from '@operato/utils'
21
+ import { ScrollbarStyles, TooltipStyles } from '@operato/styles'
22
+ import { copyToClipboard, sleep } from '@operato/utils'
23
23
 
24
24
  const FETCH_ATTACHMENT_LIST_GQL = (listParam: any) => {
25
25
  return gql`
@@ -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
 
@@ -134,23 +133,7 @@ export class OxAttachmentList extends LitElement {
134
133
  <div slot="headroom" id="headroom">
135
134
 
136
135
  <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>
136
+ <ox-filters-form></ox-filters-form>
154
137
  </div>
155
138
 
156
139
  <ox-input-file
@@ -163,9 +146,8 @@ export class OxAttachmentList extends LitElement {
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,
@@ -220,7 +202,7 @@ export class OxAttachmentList extends LitElement {
220
202
  target: HTMLElement
221
203
  ): Promise<void> => {
222
204
  var { protocol, hostname, port } = location
223
- await navigator.clipboard.writeText(`${protocol}//${hostname}:${port}${record.fullpath}`)
205
+ await copyToClipboard(`${protocol}//${hostname}:${port}${record.fullpath}`)
224
206
 
225
207
  target.setAttribute('data-tooltip', 'url copied!')
226
208
  await sleep(2000)
@@ -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>