@operato/attachment 0.2.52 → 0.3.7
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.
- package/CHANGELOG.md +72 -0
- package/dist/src/ox-attachment-list.d.ts +8 -9
- package/dist/src/ox-attachment-list.js +56 -124
- package/dist/src/ox-attachment-list.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/ox-attachment-list.ts +61 -124
- package/tsconfig.json +1 -0
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
// import './attachment-creation-card'
|
|
2
1
|
import '@operato/data-grist'
|
|
2
|
+
import '@operato/input'
|
|
3
3
|
|
|
4
4
|
import gql from 'graphql-tag'
|
|
5
5
|
import i18next from 'i18next'
|
|
6
6
|
import { css, html, LitElement, PropertyValues } from 'lit'
|
|
7
|
-
import { customElement, property, query
|
|
7
|
+
import { customElement, property, query } from 'lit/decorators.js'
|
|
8
8
|
|
|
9
|
-
import { DataGrist, QueryFilter } from '@operato/data-grist'
|
|
10
9
|
import {
|
|
11
10
|
ColumnConfig,
|
|
11
|
+
DataGrist,
|
|
12
12
|
GristData,
|
|
13
13
|
GristRecord,
|
|
14
14
|
PaginationConfig,
|
|
15
|
+
QueryFilter,
|
|
15
16
|
SortersConfig
|
|
16
|
-
} from '@operato/data-grist
|
|
17
|
+
} from '@operato/data-grist'
|
|
17
18
|
import { buildArgs, client } from '@operato/graphql'
|
|
18
19
|
import { ScrollbarStyles, TooltipStyles } from '@operato/styles'
|
|
20
|
+
import { sleep } from '@operato/utils'
|
|
19
21
|
|
|
20
22
|
const FETCH_ATTACHMENT_LIST_GQL = (listParam: any) => {
|
|
21
23
|
return gql`
|
|
@@ -30,6 +32,8 @@ const FETCH_ATTACHMENT_LIST_GQL = (listParam: any) => {
|
|
|
30
32
|
category
|
|
31
33
|
fullpath
|
|
32
34
|
path
|
|
35
|
+
createdAt
|
|
36
|
+
updatedAt
|
|
33
37
|
}
|
|
34
38
|
total
|
|
35
39
|
}
|
|
@@ -83,8 +87,6 @@ export class OxAttachmentList extends LitElement {
|
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
#headroom {
|
|
86
|
-
display: flex;
|
|
87
|
-
flex-direction: row;
|
|
88
90
|
align-items: center;
|
|
89
91
|
padding: var(--padding-default) var(--padding-wide);
|
|
90
92
|
border-top: 2px solid rgba(0, 0, 0, 0.2);
|
|
@@ -93,104 +95,68 @@ export class OxAttachmentList extends LitElement {
|
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
#filters {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
#mode {
|
|
100
|
-
width: 100px;
|
|
101
|
-
}
|
|
102
|
-
#add {
|
|
103
|
-
width: 50px;
|
|
104
|
-
text-align: right;
|
|
98
|
+
display: flex;
|
|
99
|
+
flex-direction: row;
|
|
100
|
+
justify-content: space-between;
|
|
105
101
|
}
|
|
106
102
|
|
|
107
|
-
#
|
|
108
|
-
padding: var(--padding-
|
|
109
|
-
font-size: 1em;
|
|
110
|
-
opacity: 0.5;
|
|
111
|
-
color: var(--primary-text-color);
|
|
112
|
-
cursor: pointer;
|
|
103
|
+
#filters > * {
|
|
104
|
+
padding: var(--padding-default) var(--padding-wide);
|
|
113
105
|
}
|
|
114
106
|
|
|
115
|
-
#
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
color: var(--secondary-text-color);
|
|
120
|
-
cursor: default;
|
|
121
|
-
}
|
|
122
|
-
#modes > mwc-icon:hover {
|
|
123
|
-
opacity: 1;
|
|
124
|
-
color: var(--secondary-text-color);
|
|
125
|
-
}
|
|
107
|
+
#search {
|
|
108
|
+
display: flex;
|
|
109
|
+
position: relative;
|
|
110
|
+
align-items: center;
|
|
126
111
|
|
|
127
|
-
|
|
128
|
-
background-color: var(--status-success-color);
|
|
129
|
-
border: 0;
|
|
130
|
-
border-radius: 50%;
|
|
131
|
-
padding: 5px;
|
|
132
|
-
width: 36px;
|
|
133
|
-
height: 36px;
|
|
134
|
-
cursor: pointer;
|
|
135
|
-
}
|
|
136
|
-
#add button:hover {
|
|
137
|
-
background-color: var(--focus-background-color);
|
|
138
|
-
box-shadow: var(--box-shadow);
|
|
139
|
-
}
|
|
140
|
-
#add button mwc-icon {
|
|
141
|
-
font-size: 2em;
|
|
142
|
-
color: var(--theme-white-color);
|
|
112
|
+
--mdc-icon-size: 20px;
|
|
143
113
|
}
|
|
144
114
|
|
|
145
|
-
#
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
#filters [type='text'] {
|
|
115
|
+
#search [type='text'] {
|
|
116
|
+
flex: 1;
|
|
149
117
|
background-color: transparent;
|
|
150
118
|
border: 0;
|
|
151
119
|
border-bottom: var(--border-dark-color);
|
|
152
120
|
padding: var(--padding-narrow) var(--padding-narrow) 7px 25px;
|
|
153
121
|
font-size: var(--fontsize-large);
|
|
154
|
-
}
|
|
155
|
-
#filters [type='text']:focus {
|
|
156
122
|
outline: none;
|
|
157
123
|
}
|
|
158
|
-
|
|
124
|
+
|
|
125
|
+
#search mwc-icon {
|
|
159
126
|
position: absolute;
|
|
160
|
-
top: 3px;
|
|
161
127
|
color: var(--secondary-color);
|
|
162
128
|
}
|
|
163
|
-
|
|
164
|
-
|
|
129
|
+
|
|
130
|
+
select {
|
|
131
|
+
border: 0;
|
|
132
|
+
outline: none;
|
|
133
|
+
text-align: right;
|
|
165
134
|
}
|
|
166
135
|
|
|
167
136
|
@media only screen and (max-width: 460px) {
|
|
168
|
-
#
|
|
169
|
-
|
|
137
|
+
#filters {
|
|
138
|
+
flex-direction: column;
|
|
170
139
|
}
|
|
171
140
|
}
|
|
172
141
|
`
|
|
173
142
|
]
|
|
174
143
|
|
|
175
144
|
@property({ type: Array }) categories: any[] = ['audio', 'video', 'image', 'text', 'application']
|
|
176
|
-
@property({ type: String }) mode: 'GRID' | 'LIST' | 'CARD' = 'CARD'
|
|
177
145
|
@property({ type: String }) category: string = ''
|
|
178
146
|
@property({ type: Boolean }) creatable: boolean = false
|
|
179
147
|
|
|
180
|
-
@state() private _total: number = 0
|
|
181
|
-
@state() private _page: number = 1
|
|
182
|
-
|
|
183
148
|
@query('ox-grist') private grist!: DataGrist
|
|
149
|
+
@query('ox-input-file') fileUploader!: any
|
|
184
150
|
|
|
185
151
|
render() {
|
|
186
|
-
const mode = this.mode || 'CARD'
|
|
187
|
-
|
|
188
152
|
return html`
|
|
189
|
-
<ox-grist .config=${this.gristConfig} .mode=${
|
|
153
|
+
<ox-grist .config=${this.gristConfig} .mode=${'CARD'} auto-fetch .fetchHandler=${this.fetchHandler.bind(this)}>
|
|
190
154
|
<div slot="headroom" id="headroom">
|
|
191
155
|
<div id="filters">
|
|
192
|
-
<
|
|
193
|
-
|
|
156
|
+
<div id="search">
|
|
157
|
+
<mwc-icon>search</mwc-icon>
|
|
158
|
+
<input type="text"/>
|
|
159
|
+
</div>
|
|
194
160
|
|
|
195
161
|
<select
|
|
196
162
|
@change=${(e: Event) => {
|
|
@@ -198,7 +164,7 @@ export class OxAttachmentList extends LitElement {
|
|
|
198
164
|
this.requestUpdate()
|
|
199
165
|
}}
|
|
200
166
|
>
|
|
201
|
-
<option value=""
|
|
167
|
+
<option value="">${i18next.t('text.please choose a category')}</option>
|
|
202
168
|
${this.categories.map(
|
|
203
169
|
category =>
|
|
204
170
|
html` <option value=${category} ?selected=${this.category == category}>${category}</option> `
|
|
@@ -206,24 +172,12 @@ export class OxAttachmentList extends LitElement {
|
|
|
206
172
|
</select>
|
|
207
173
|
</div>
|
|
208
174
|
|
|
209
|
-
<
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
<!-- ${this.creatable
|
|
216
|
-
? html`
|
|
217
|
-
<attachment-creation-card
|
|
218
|
-
class="card create"
|
|
219
|
-
.categories=${this.categories}
|
|
220
|
-
.defaultCategory=${this.category}
|
|
221
|
-
@create-attachment=${(e: CustomEvent) => this.onCreateAttachment(e)}
|
|
222
|
-
@file-drop=${(e: CustomEvent) => this.onAttachmentDropped(e)}
|
|
223
|
-
></attachment-creation-card>
|
|
224
|
-
`
|
|
225
|
-
: undefined} -->
|
|
226
|
-
</div>
|
|
175
|
+
<ox-input-file
|
|
176
|
+
accept="*/*"
|
|
177
|
+
multiple="true"
|
|
178
|
+
hide-filelist
|
|
179
|
+
@change=${this.onCreateAttachment.bind(this)}
|
|
180
|
+
></ox-input-file>
|
|
227
181
|
</ox-grist>
|
|
228
182
|
`
|
|
229
183
|
}
|
|
@@ -274,7 +228,8 @@ export class OxAttachmentList extends LitElement {
|
|
|
274
228
|
data: GristData,
|
|
275
229
|
column: ColumnConfig,
|
|
276
230
|
record: GristRecord,
|
|
277
|
-
rowIndex: number
|
|
231
|
+
rowIndex: number,
|
|
232
|
+
target: HTMLElement
|
|
278
233
|
): void => {
|
|
279
234
|
window.open(record.fullpath, '_blank')
|
|
280
235
|
}
|
|
@@ -290,15 +245,15 @@ export class OxAttachmentList extends LitElement {
|
|
|
290
245
|
data: GristData,
|
|
291
246
|
column: ColumnConfig,
|
|
292
247
|
record: GristRecord,
|
|
293
|
-
rowIndex: number
|
|
248
|
+
rowIndex: number,
|
|
249
|
+
target: HTMLElement
|
|
294
250
|
): Promise<void> => {
|
|
295
251
|
var { protocol, hostname, port } = location
|
|
296
252
|
await navigator.clipboard.writeText(`${protocol}//${hostname}:${port}${record.fullpath}`)
|
|
297
253
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
// this.removeAttribute('data-tooltip')
|
|
254
|
+
target.setAttribute('data-tooltip', 'url copied!')
|
|
255
|
+
await sleep(2000)
|
|
256
|
+
target.removeAttribute('data-tooltip')
|
|
302
257
|
}
|
|
303
258
|
}
|
|
304
259
|
},
|
|
@@ -312,7 +267,8 @@ export class OxAttachmentList extends LitElement {
|
|
|
312
267
|
data: GristData,
|
|
313
268
|
column: ColumnConfig,
|
|
314
269
|
record: GristRecord,
|
|
315
|
-
rowIndex: number
|
|
270
|
+
rowIndex: number,
|
|
271
|
+
target: HTMLElement
|
|
316
272
|
): Promise<void> => {
|
|
317
273
|
await this.deleteAttachment(record.id!)
|
|
318
274
|
this.refreshAttachments()
|
|
@@ -329,7 +285,8 @@ export class OxAttachmentList extends LitElement {
|
|
|
329
285
|
data: GristData,
|
|
330
286
|
column: ColumnConfig,
|
|
331
287
|
record: GristRecord,
|
|
332
|
-
rowIndex: number
|
|
288
|
+
rowIndex: number,
|
|
289
|
+
target: HTMLElement
|
|
333
290
|
): void => {
|
|
334
291
|
const element = document.createElement('a')
|
|
335
292
|
element.setAttribute('href', record.fullpath)
|
|
@@ -401,7 +358,9 @@ export class OxAttachmentList extends LitElement {
|
|
|
401
358
|
selectable: {
|
|
402
359
|
multiple: true
|
|
403
360
|
},
|
|
404
|
-
handlers: {
|
|
361
|
+
handlers: {
|
|
362
|
+
click: 'select-row-toggle'
|
|
363
|
+
},
|
|
405
364
|
classifier: function (
|
|
406
365
|
record: GristRecord,
|
|
407
366
|
rowIndex: number
|
|
@@ -441,19 +400,10 @@ export class OxAttachmentList extends LitElement {
|
|
|
441
400
|
)
|
|
442
401
|
}
|
|
443
402
|
|
|
444
|
-
async onAttachmentDropped(e: CustomEvent) {
|
|
445
|
-
var files = e.detail
|
|
446
|
-
|
|
447
|
-
await this.createAttachments('', files)
|
|
448
|
-
this.refreshAttachments()
|
|
449
|
-
}
|
|
450
|
-
|
|
451
403
|
async onCreateAttachment(e: CustomEvent) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
files = Array.from(files)
|
|
404
|
+
const files = e.detail
|
|
455
405
|
|
|
456
|
-
await this.createAttachments(
|
|
406
|
+
await this.createAttachments(files)
|
|
457
407
|
this.refreshAttachments()
|
|
458
408
|
}
|
|
459
409
|
|
|
@@ -465,18 +415,6 @@ export class OxAttachmentList extends LitElement {
|
|
|
465
415
|
|
|
466
416
|
async refreshAttachments() {
|
|
467
417
|
this.grist.fetch()
|
|
468
|
-
// var attachments = await this.getAttachments()
|
|
469
|
-
// this.attachments = [...attachments]
|
|
470
|
-
|
|
471
|
-
// var creationCard = this.shadowRoot.querySelector('attachment-creation-card')
|
|
472
|
-
// if (creationCard) {
|
|
473
|
-
// creationCard.reset()
|
|
474
|
-
// }
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
async appendAttachments() {
|
|
478
|
-
// var attachments = await this.getAttachments({ page: this._page + 1 })
|
|
479
|
-
// this.attachments = [...this.attachments, ...attachments]
|
|
480
418
|
}
|
|
481
419
|
|
|
482
420
|
async getAttachments({
|
|
@@ -515,17 +453,16 @@ export class OxAttachmentList extends LitElement {
|
|
|
515
453
|
return attachmentListResponse?.data?.attachments || {}
|
|
516
454
|
}
|
|
517
455
|
|
|
518
|
-
async createAttachments(
|
|
456
|
+
async createAttachments(files: File[]) {
|
|
519
457
|
/*
|
|
520
458
|
ref. https://github.com/jaydenseric/graphql-multipart-request-spec#client
|
|
521
|
-
- TODO support multiple file upload
|
|
522
459
|
*/
|
|
523
460
|
|
|
524
|
-
await client.mutate({
|
|
461
|
+
const response = await client.mutate({
|
|
525
462
|
mutation: CREATE_ATTACHMENTS_GQL,
|
|
526
463
|
variables: {
|
|
527
464
|
attachments: files.map(file => {
|
|
528
|
-
return {
|
|
465
|
+
return { file }
|
|
529
466
|
})
|
|
530
467
|
},
|
|
531
468
|
context: {
|