1
1
<template >
2
- <div class =" markdown-editor" @click =" onClickEditor" >
3
- <textarea />
2
+ <div >
3
+ <div class =" upload-button" >
4
+ <Actions
5
+ container =" .upload-button"
6
+ default-icon =" icon-picture"
7
+ menu-align =" right"
8
+ >
9
+ <ActionButton
10
+ icon =" icon-upload"
11
+ :close-after-click =" true"
12
+ @click =" onClickUpload"
13
+ >
14
+ {{ t('notes', 'Upload image') }}
15
+ </ActionButton >
16
+ <ActionButton
17
+ icon =" icon-picture"
18
+ :close-after-click =" true"
19
+ @click =" onClickSelect"
20
+ >
21
+ {{ t('notes', 'Insert image') }}
22
+ </ActionButton >
23
+ </Actions >
24
+ </div >
25
+ <div class =" markdown-editor" @click =" onClickEditor" >
26
+ <textarea />
27
+ </div >
4
28
</div >
5
29
</template >
6
30
<script >
@@ -9,10 +33,22 @@ import EasyMDE from 'easymde'
9
33
import axios from ' @nextcloud/axios'
10
34
import { generateUrl } from ' @nextcloud/router'
11
35
import store from ' ../store'
36
+ import { showError } from ' @nextcloud/dialogs'
37
+ import ' @nextcloud/dialogs/styles/toast.scss'
38
+ import {
39
+ Actions ,
40
+ ActionButton ,
41
+ } from ' @nextcloud/vue'
42
+ import { basename , relative } from ' path'
12
43
13
44
export default {
14
45
name: ' EditorEasyMDE' ,
15
46
47
+ components: {
48
+ Actions,
49
+ ActionButton,
50
+ },
51
+
16
52
props: {
17
53
value: {
18
54
type: String ,
@@ -26,6 +62,10 @@ export default {
26
62
type: String ,
27
63
required: true ,
28
64
},
65
+ notecategory: {
66
+ type: String ,
67
+ required: true ,
68
+ },
29
69
},
30
70
31
71
data () {
@@ -66,7 +106,7 @@ export default {
66
106
methods: {
67
107
initialize () {
68
108
const config = Object .assign ({
69
- element: this .$el .firstElementChild ,
109
+ element: this .$el .lastElementChild . firstElementChild ,
70
110
initialValue: this .value ,
71
111
renderingConfig: {},
72
112
}, this .config )
@@ -132,9 +172,8 @@ export default {
132
172
},
133
173
134
174
async onClickSelect () {
135
- const apppath = ' /' + store .state .app .settings .notesPath
136
- const categories = store .getters .getCategories ()
137
- const currentNotePath = apppath + ' /' + categories
175
+ const apppath = ' /' + store .state .app .settings .notesPath + ' /'
176
+ const currentNotePath = apppath + this .notecategory
138
177
139
178
const doc = this .mde .codemirror .getDoc ()
140
179
const cursor = this .mde .codemirror .getCursor ()
@@ -149,14 +188,10 @@ export default {
149
188
)
150
189
return
151
190
}
152
- const noteLevel = ((currentNotePath + ' /' ).split (' /' ).length ) - 1
153
- const imageLevel = (path .split (' /' ).length - 1 )
154
- const upwardsLevel = noteLevel - imageLevel
155
- for (let i = 0 ; i < upwardsLevel; i++ ) {
156
- path = ' ../' + path
157
- }
158
- path = path .replace (apppath + ' /' , ' ' )
159
- doc .replaceRange (' ' , { line: cursor .line })
191
+ const label = basename (path)
192
+ const relativePath = relative (currentNotePath, path)
193
+ doc .replaceRange (' \n ' , { line: cursor .line })
194
+ this .mde .codemirror .focus ()
160
195
},
161
196
false ,
162
197
[' image/jpeg' , ' image/png' ],
@@ -167,6 +202,7 @@ export default {
167
202
},
168
203
169
204
async onClickUpload () {
205
+ const cm = this .mde .codemirror
170
206
const doc = this .mde .codemirror .getDoc ()
171
207
const cursor = this .mde .codemirror .getCursor ()
172
208
const id = this .noteid
@@ -176,16 +212,21 @@ export default {
176
212
temporaryInput .onchange = async function () {
177
213
const data = new FormData ()
178
214
data .append (' file' , temporaryInput .files [0 ])
179
- const response = await axios ({
180
- method: ' POST' ,
181
- url: generateUrl (' apps/notes' ) + ' /notes/' + id + ' /attachment' ,
182
- data,
183
- })
184
- const name = response .data [0 ].filename
185
- const position = {
186
- line: cursor .line ,
187
- }
188
- doc .replaceRange (' ' , position)
215
+ const originalFilename = temporaryInput .files [0 ].name
216
+
217
+ axios .post (generateUrl (' apps/notes' ) + ' /notes/' + id + ' /attachment' , data)
218
+ .then ((response ) => {
219
+ const name = response .data .filename
220
+ const position = {
221
+ line: cursor .line ,
222
+ }
223
+ doc .replaceRange (' \n ' , position)
224
+ cm .focus ()
225
+ })
226
+ .catch ((error ) => {
227
+ console .error (error)
228
+ showError (t (' notes' , ' The file was not uploaded. Check your serverlogs.' ),)
229
+ })
189
230
}
190
231
temporaryInput .click ()
191
232
},
@@ -320,4 +361,12 @@ export default {
320
361
opacity : 0.5 ;
321
362
text-decoration : line-through ;
322
363
}
364
+
365
+ .upload-button {
366
+ position : fixed ;
367
+ right : 64px ;
368
+ z-index : 10 ;
369
+ height : 40px ;
370
+ margin-right : 5px ;
371
+ }
323
372
</style >
0 commit comments