1
1
import { action } from "@ember/object" ;
2
2
import { inject as service } from "@ember/service" ;
3
3
import { tracked } from "@glimmer/tracking" ;
4
- import { restartableTask , dropTask } from "ember-concurrency" ;
4
+ import { task } from "ember-concurrency" ;
5
5
import lang from "flatpickr/dist/l10n" ;
6
6
import { DateTime } from "luxon" ;
7
7
@@ -40,14 +40,19 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
40
40
return formats [ this . locale ] ?? defaultFormat ;
41
41
}
42
42
43
+ get isWordProcessingFormat ( ) {
44
+ return [
45
+ "application/vnd.oasis.opendocument.text" ,
46
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
47
+ ] . includes ( this . args . document . latestFile ?. value ?. mimeType ) ;
48
+ }
49
+
50
+ get displayWebDAVButton ( ) {
51
+ return this . config . enableWebDAV && this . isWordProcessingFormat ;
52
+ }
53
+
43
54
get displayConvertButton ( ) {
44
- return (
45
- this . config . enablePDFConversion &&
46
- [
47
- "application/vnd.oasis.opendocument.text" ,
48
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
49
- ] . includes ( this . args . document . latestFile ?. value ?. mimeType )
50
- ) ;
55
+ return this . config . enablePDFConversion && this . isWordProcessingFormat ;
51
56
}
52
57
53
58
@action updateDocumentTitle ( { target : { value : title } } ) {
@@ -83,38 +88,37 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
83
88
this . documents . enableShortcuts ( ) ;
84
89
}
85
90
86
- @ restartableTask * saveDocument ( event ) {
91
+ saveDocument = task ( { restartable : true } , async ( event ) => {
87
92
event ?. preventDefault ( ) ;
88
93
89
94
try {
90
- yield this . args . document . save ( ) ;
95
+ await this . args . document . save ( ) ;
91
96
this . resetState ( ) ;
92
97
this . notification . success ( this . intl . t ( "alexandria.success.update" ) ) ;
93
98
} catch ( error ) {
94
99
this . args . document . rollbackAttributes ( ) ;
95
100
new ErrorHandler ( this , error ) . notify ( "alexandria.errors.update" ) ;
96
101
}
97
- }
102
+ } ) ;
98
103
99
- @ dropTask * uploadReplacement ( event ) {
104
+ uploadReplacement = task ( { drop : true } , async ( event ) => {
100
105
try {
101
106
const [ file ] = event . target . files ;
102
- yield this . documents . replace ( this . args . document , file ) ;
107
+ await this . documents . replace ( this . args . document , file ) ;
103
108
} catch ( error ) {
104
109
new ErrorHandler ( this , error ) . notify (
105
110
"alexandria.errors.replace-document" ,
106
111
) ;
107
112
}
108
- }
113
+ } ) ;
109
114
110
- @dropTask
111
- * convertDocument ( event ) {
115
+ convertDocument = task ( { drop : true } , async ( event ) => {
112
116
event ?. preventDefault ( ) ;
113
117
try {
114
118
const modelName = "document" ;
115
119
const adapter = this . store . adapterFor ( modelName ) ;
116
120
const url = adapter . buildURL ( modelName , this . args . document . id ) ;
117
- yield this . fetch . fetch ( `${ url } /convert` , {
121
+ await this . fetch . fetch ( `${ url } /convert` , {
118
122
method : "POST" ,
119
123
} ) ;
120
124
@@ -124,5 +128,18 @@ export default class SingleDocumentDetailsComponent extends DocumentCard {
124
128
} catch ( error ) {
125
129
new ErrorHandler ( this , error ) . notify ( "alexandria.errors.convert-pdf" ) ;
126
130
}
127
- }
131
+ } ) ;
132
+
133
+ openWebDAV = task ( { drop : true } , async ( event ) => {
134
+ event ?. preventDefault ( ) ;
135
+ try {
136
+ const fileId = this . args . document . latestFile . value . id ;
137
+
138
+ const file = await this . store . findRecord ( "file" , fileId ) ;
139
+
140
+ window . open ( file . webdavUrl , "_blank" ) ;
141
+ } catch ( error ) {
142
+ new ErrorHandler ( this , error ) . notify ( "alexandria.errors.open-webdav" ) ;
143
+ }
144
+ } ) ;
128
145
}
0 commit comments