-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2975 from Tangerine-Community/2974_prcess_monitor…
…ing_server Implement on server the process-monitoring code from client PR #2825
- Loading branch information
Showing
11 changed files
with
221 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {LitElement, html, css} from 'lit-element'; | ||
import {customElement, property} from "lit-element/lib/decorators"; | ||
import '@polymer/paper-progress/paper-progress.js'; | ||
|
||
@customElement('loading-ui') | ||
export class LoadingUiComponent extends LitElement { | ||
static styles = css` | ||
:host { | ||
display: block; | ||
} | ||
.loading-text { | ||
display: flex; | ||
width: 50%; | ||
height: 100px; | ||
margin: auto; | ||
margin-top: 200px; | ||
border-radius: 10px; | ||
border: 3px dashed #1c87c9; | ||
align-items: center; | ||
justify-content: center; | ||
background: var(--primary-color); | ||
color:white; | ||
opacity: 100%; | ||
font-size: x-large; | ||
} | ||
`; | ||
|
||
render() { | ||
return html` | ||
<div class="loading-text" @click=${this.escape}> | ||
<paper-progress indeterminate></paper-progress> | ||
</div> | ||
`; | ||
} | ||
|
||
escape() { | ||
if (confirm(`${window['T'].translate('Please only leave this dialog if you believe there is an error in the application.')}`)) { | ||
window['T'].process.clear() | ||
} | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'loading-ui': LoadingUiComponent; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {Injectable} from "@angular/core"; | ||
import {CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot} from "@angular/router"; | ||
import {Observable} from "rxjs"; | ||
import {ProcessMonitorService} from "../_services/process-monitor.service"; | ||
import {TangyFormsPlayerComponent} from "../../tangy-forms/tangy-forms-player/tangy-forms-player.component"; | ||
|
||
@Injectable() | ||
export class ProcessGuard implements CanDeactivate<TangyFormsPlayerComponent> { | ||
constructor( | ||
private processMonitorService:ProcessMonitorService | ||
) { } | ||
|
||
canDeactivate(component: TangyFormsPlayerComponent, | ||
currentRoute: ActivatedRouteSnapshot, | ||
currentState: RouterStateSnapshot, | ||
nextState?: RouterStateSnapshot): Observable<boolean>|Promise<boolean>|boolean { | ||
// If no processes being busy | ||
if (this.processMonitorService.processes.length > 0) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
|
||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
editor/src/app/shared/_services/process-monitor.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Subject } from 'rxjs'; | ||
import { v4 as UUID } from 'uuid'; | ||
import { Injectable } from '@angular/core'; | ||
|
||
interface Process { | ||
id:string | ||
name:string | ||
description:string | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
class ProcessMonitorService { | ||
|
||
// When number of processes go from 0 to 1, this Subject will emit true. | ||
busy = new Subject() | ||
// When number of processes go to 0, this Subject will emit true. | ||
done = new Subject() | ||
// A list of the active processes. | ||
processes:Array<Process> = [] | ||
|
||
constructor() { | ||
} | ||
|
||
hasNoProcesses = this.processes.length === 0 | ||
? true | ||
: false | ||
|
||
start(name, description):Process { | ||
const process = <Process>{ | ||
id: UUID(), | ||
name, | ||
description | ||
} | ||
|
||
this.processes.push(process) | ||
if (this.hasNoProcesses) { | ||
this.busy.next(true) | ||
} | ||
return process | ||
} | ||
|
||
stop(pid:string) { | ||
this.processes = this.processes.filter(process => process.id !== pid) | ||
if (this.processes.length === 0) { | ||
this.done.next(true) | ||
} | ||
} | ||
|
||
clear() { | ||
this.processes = [] | ||
this.done.next(true) | ||
} | ||
|
||
} | ||
|
||
export { ProcessMonitorService }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters