vikunja-frontend/src/services/attachment.ts

64 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-11-24 14:16:24 +01:00
import AbstractService from './abstractService'
2022-07-21 00:42:36 +02:00
import AttachmentModel, { type IAttachment } from '../models/attachment'
2020-03-02 21:55:22 +01:00
import {formatISO} from 'date-fns'
import {downloadBlob} from '@/helpers/downloadBlob'
2022-07-21 00:42:36 +02:00
import type { IFile } from '@/models/file'
2019-11-24 14:16:24 +01:00
2022-07-20 21:15:35 +02:00
export default class AttachmentService extends AbstractService<AttachmentModel> {
2019-11-24 14:16:24 +01:00
constructor() {
super({
create: '/tasks/{taskId}/attachments',
getAll: '/tasks/{taskId}/attachments',
delete: '/tasks/{taskId}/attachments/{id}',
2019-11-24 14:16:24 +01:00
})
}
2022-07-21 00:42:36 +02:00
processModel(model: IAttachment) {
model.created = formatISO(new Date(model.created))
return model
}
2019-11-24 14:16:24 +01:00
useCreateInterceptor() {
return false
}
modelFactory(data) {
return new AttachmentModel(data)
}
modelCreateFactory(data) {
// Success contains the uploaded attachments
data.success = (data.success === null ? [] : data.success).map(a => {
return this.modelFactory(a)
})
return data
}
2022-07-21 00:42:36 +02:00
getBlobUrl(model: IAttachment) {
return AbstractService.prototype.getBlobUrl.call(this, '/tasks/' + model.taskId + '/attachments/' + model.id)
Add easymde & markdown preview for editing descriptions and comments (#183) Make sure no text from previous mounts is left in the editor text field Make preview not the default when rendering descrition settings Add option to show editor by default while still having the option to show preview Add option to show editor by default while still having the option to show preview Use editor component for edit labels Use editor component for edit team Use editor component for edit namespace Use editor component for edit list Use editor component for edit task Make sure we find all checkboxes Fix checking wrong checkbox Make finding and replacing checkboxes in a function actually work Add upading text with checked checkboxes Lazy load editor Remove preview since we have a better one Make easymde smaller by default Add image upload from comments Rename easymde component to editor Only show preview button if editing is currently active Make editor tabs look better when commenting Make comments meta look better Don't try to update if the value was initially set Use editor to render and edit comments Make preview optional Make tabs look better Don't switch to preview after editing Centralize attachment state Render markdown by default Fix title being "null" Fix loading attachment images Add standalone preview Fix callback url Add onsuccess callback Add file upload Fix date parsing once and for all Add more props for upload and such Fix editor border color Fix changing text after mounting Add link to guide Fix sizing of icons Add timeout for changes Add all easymde icons Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/183
2020-07-14 21:26:05 +02:00
}
2022-07-21 00:42:36 +02:00
async download(model: IAttachment) {
const url = await this.getBlobUrl(model)
return downloadBlob(url, model.file.name)
2019-11-24 14:16:24 +01:00
}
/**
* Uploads a file to the server
* @param files
* @returns {Promise<any|never>}
*/
2022-07-21 00:42:36 +02:00
create(model: IAttachment, files: IFile[]) {
const data = new FormData()
2019-11-24 14:16:24 +01:00
for (let i = 0; i < files.length; i++) {
// TODO: Validation of file size
data.append('files', new Blob([files[i]]), files[i].name)
2019-11-24 14:16:24 +01:00
}
return this.uploadFormData(
2019-11-24 14:16:24 +01:00
this.getReplacedRoute(this.paths.create, model),
data,
2019-11-24 14:16:24 +01:00
)
}
}