code refactoring (Yann, Liana)

pull/3094/head
LianaHus 6 years ago
parent 71d95764f3
commit 29d7fd349b
  1. 90
      src/app/files/fileManager.js

@ -137,63 +137,57 @@ class FileManager extends FileSystemApi {
async setFile (path, content) { async setFile (path, content) {
if (this.currentRequest) { if (this.currentRequest) {
let reject = false let reject = false
let savedAsCopy = false let saveAsCopy = false
let accept = false let actions = (toaster) => { return yo`
let actions = (toaster) => { <div class="container ml-1">
return yo` <button class="btn btn-primary btn-sm m-1" onclick=${(e) => {
<div class="container ml-1"> reject = false;
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => { e.target.innerHTML = 'Accepted';
accept = true; toaster.hide();
e.target.innerHTML = 'Accepted'; toaster.forceResolve()
const fileProvider = this.fileProviderOf(path) }}>
if (!fileProvider) return Accept
if (!fileProvider.set(path, content)) { </button>
return modalDialogCustom.alert('Failed to create a file ' + path) <button class="btn btn-primary btn-sm m-1" onclick=${(e) => {
} reject = true;
this.syncEditor(path) e.target.innerHTML = 'Canceled';
this.switchFile(path) toaster.hide()
toaster.hide() }}>
}}> Cancel
Accept </button>
</button> <button class="btn btn-primary btn-sm m-1" onclick=${(e) => {
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => { if (saveAsCopy) return
reject = true; const fileProvider = this.fileProviderOf(path)
e.target.innerHTML = 'Canceled'; if (fileProvider) {
toaster.hide() helper.createNonClashingNameWithPrefix(path, fileProvider, '', (error, copyName) => {
}}> if (error) {
Cancel console.log('createNonClashingNameWithPrefix', error)
</button> copyName = path + '.' + this.currentRequest.from
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => { }
if (savedAsCopy) return this._setFileInternal(copyName, content)
savedAsCopy = true this.switchFile(copyName)
const fileProvider = this.fileProviderOf(path)
if (!fileProvider) return
helper.createNonClashingNameWithPrefix(path, fileProvider, '', (error, newFile) => {
if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error)
if (!fileProvider.set(newFile, content)) return modalDialogCustom.alert('Failed to create a file ' + newFile)
this.switchFile(newFile)
this.syncEditor(path)
}) })
e.target.innerHTML = 'Saved' }
toaster.hide() e.target.innerHTML = 'Saved'
}}> saveAsCopy = true
Save As Copy toaster.hide()
</button> }}>
</div> Save As Copy
` </button>
} </div>
`}
await toaster(yo` await toaster(yo`
<div> <div>
<i class="fas fa-exclamation-triangle text-danger mr-1"></i> <i class="fas fa-exclamation-triangle text-danger mr-1"></i>
<span> <span>
${this.currentRequest.from}<span class="text-danger"> is trying to modify </span>${path} ${this.currentRequest.from}<span class="text-danger font-weight-bold"> is trying to modify </span>${path}
</span> </span>
</div> </div>
`, actions, { time: 4000 }) `, actions, { time: 5000 })
if (reject) throw new Error(`set file operation on ${path} aborted by user.`) if (reject) throw new Error(`set file operation on ${path} aborted by user.`)
if (accept || savedAsCopy) return if (saveAsCopy) return
else this._setFileInternal(path, content)
} }
this._setFileInternal(path, content)
} }
_setFileInternal (path, content) { _setFileInternal (path, content) {

Loading…
Cancel
Save