Skip to content

Commit

Permalink
confirm overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
bunsenstraat committed Feb 2, 2022
1 parent 0b3c195 commit fbbaa21
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
58 changes: 47 additions & 11 deletions src/app/step/+state/step.service.ts
@@ -1,6 +1,8 @@
import {
Component,
Inject,
Injectable
Injectable,
Input
} from '@angular/core'
import {
ID
Expand Down Expand Up @@ -34,6 +36,17 @@ import {
StepStore
} from './step.store'

import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';

@Component({
selector: 'ngbd-modal-confirm',
templateUrl: '../modal/confirm-write-modal.html',
})
export class NgbdModalConfirm {
@Input() fileName;
constructor(public modal: NgbActiveModal) {}
}

/** Create the path for the file manager based on a step */
function getFilePath(file: string): string {
const name = file.split('/')
Expand All @@ -53,7 +66,8 @@ export class StepService {
private store: StepStore,
private query: StepQuery,
private spinner: NgxSpinnerService,
private toastr: ToastrService // private toaster: NotificationStore
private toastr: ToastrService, // private toaster: NotificationStore
private _modalService: NgbModal
) {}

async get(index: number, step: Step) {
Expand Down Expand Up @@ -140,7 +154,23 @@ export class StepService {
this.store.setLoading(false)
}

async askPermissions(path: string) {
let result = 'ok'
if(await this.remix.call('fileManager', 'exists' as any, path)){
console.log('exist')
const ref:NgbModalRef = this._modalService.open(NgbdModalConfirm)
ref.componentInstance.fileName = path
try {
result = await ref.result
} catch(e) {
result = 'no'
}
}
return result
}

async displayFileInIDE(step: Step) {

let tid

// Get content from account or step
Expand All @@ -165,10 +195,12 @@ export class StepService {
tid = this.toastr.info(`loading ${path} into IDE`, `loading`, {
timeOut: 0,
}).toastId
this.spinner.show()

path = `.learneth/${workshop.name}/${step.name}/${path}`
await this.remix.call('fileManager', 'setFile', path, content)
await this.remix.call('fileManager', 'switchFile', `browser/${path}`)
const permission = await this.askPermissions(path)
this.spinner.show()
if(permission == 'ok') await this.remix.call('fileManager', 'setFile', path, content)
await this.remix.call('fileManager', 'switchFile', `${path}`)
this.spinner.hide()
this.toastr.remove(tid)
} else {
Expand Down Expand Up @@ -197,21 +229,23 @@ export class StepService {
})

// Run tests
this.spinner.show()

const workshop = this.workshopQuery.getActive()

let path: string
if (step.solidity.file) {
path = getFilePath(step.solidity.file)
path = `.learneth/${workshop.name}/${step.name}/${path}`
await this.remix.call('fileManager', 'switchFile', `browser/${path}`)
await this.remix.call('fileManager', 'switchFile', `${path}`)
}

console.log('testing ', step.test.content)

path = getFilePath(step.test.file)
path = `.learneth/${workshop.name}/${step.name}/${path}`
await this.remix.call('fileManager', 'setFile', path, step.test.content)
const permission = await this.askPermissions(path)
this.spinner.show()
if( permission == 'ok') await this.remix.call('fileManager', 'setFile', path, step.test.content)
let result: any


Expand Down Expand Up @@ -269,11 +303,13 @@ export class StepService {
const tid = this.toastr.info(`loading answer into IDE`, `loading`, {
timeOut: 0,
}).toastId
this.spinner.show()

const workshop = this.workshopQuery.getActive()
path = `.learneth/${workshop.name}/${step.name}/${path}`
await this.remix.call('fileManager', 'setFile', path, content)
await this.remix.call('fileManager', 'switchFile', `browser/${path}`)
const permission = await this.askPermissions(path)
this.spinner.show()
if( permission == 'ok') await this.remix.call('fileManager', 'setFile', path, content)
await this.remix.call('fileManager', 'switchFile', `${path}`)
this.spinner.hide()
this.toastr.remove(tid)
} else {
Expand Down
14 changes: 14 additions & 0 deletions src/app/step/modal/confirm-write-modal.html
@@ -0,0 +1,14 @@
<div class="modal-header">
<h4 class="modal-title" id="modal-title">Overwrite file?</h4>
<button type="button" class="close" aria-label="Close button" aria-describedby="modal-title" (click)="modal.dismiss('cancel')">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body text-break">
<p><strong>Are you sure you want overwrite this file: {{fileName}} ?</strong></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="modal.dismiss('cancel')">No</button>
<button type="button" ngbAutofocus class="btn btn-success" (click)="modal.close('ok')">Yes</button>
</div>

3 changes: 2 additions & 1 deletion src/app/step/view/view.component.ts
Expand Up @@ -170,7 +170,8 @@ export class StepViewComponent implements OnInit {
this.toastr.clear()
this.errorLoadingFile = false
})
.catch((_) => {
.catch((e) => {
console.log(e)
this.errorLoadingFile = true
this.spinner.hide()
this.toastr.clear()
Expand Down

0 comments on commit fbbaa21

Please sign in to comment.