-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
477 additions
and
104 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
94 changes: 94 additions & 0 deletions
94
src/app/components/plugin-manager/plugin-manager.component.html
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,94 @@ | ||
<nz-modal | ||
[nzVisible]="showPluginManager" | ||
(nzVisibleChange)="toggleDialogChange.next($event)" | ||
[nzTitle]="modalTitle" | ||
[nzContent]="modalContent" | ||
[nzFooter]="modalFooter" | ||
[nzWidth]="870" | ||
(nzOnCancel)="toggleDialogChange.next($event)" | ||
> | ||
<ng-template #modalTitle> | ||
<div class="app-dialog-header"> | ||
<div class="app-dialog-title">{{ 'PLUGINS_TEXT' | translate }}</div> | ||
{{ 'PLUGINS_SUB_TEXT' | translate }} | ||
</div> | ||
</ng-template> | ||
|
||
<ng-template #modalContent> | ||
<div class="app-dialog-body"> | ||
<div class="app-dialog-section"> | ||
<div class="plugin-manager-wrapper"> | ||
<div class="plugin-manager__list"> | ||
<div | ||
*ngFor="let item of (remotePlugins$ | async);trackBy: trackByName;" | ||
class="plugin-manager__list-item" | ||
[ngClass]="{ 'plugin-manager__list-item--selected': selectedPluginItem && selectedPluginItem.name === item.name }" | ||
(click)="onSelectPlugin(item)" | ||
> | ||
<div class="plugin-manager__list-item-name"> | ||
{{ item?.manifest?.display_name || item.name }} | ||
<div class="plugin-manager__list-item-version"> | ||
{{ item?.manifest?.version || item.version }} | ||
</div> | ||
</div> | ||
<div class="plugin-manager__list-item-description"> | ||
{{ item?.manifest?.description || item.description }} | ||
</div> | ||
</div> | ||
</div> | ||
<div class="plugin-manager__item-details"> | ||
<ng-container | ||
*ngIf="selectedPluginItem" | ||
> | ||
<div class="plugin-manager__item-details-name"> | ||
{{ selectedPluginItem?.manifest?.display_name || selectedPluginItem.name }} | ||
<div | ||
class="plugin-manager__item-details-unique-name" | ||
[attr.title]="'PLUGIN_UNIQUE_NAME_TEXT' | translate" | ||
> | ||
{{ selectedPluginItem.name }} | ||
</div> | ||
</div> | ||
<div class="plugin-manager__item-details-actions"> | ||
<button | ||
*ngIf="!isPluginInstalled(selectedPluginItem.name)" | ||
class="app-button active-grey" | ||
(click)="onAddPlugin(selectedPluginItem.name)" | ||
> | ||
<app-icon name="plus-circle"></app-icon> | ||
{{ 'PLUGIN_ADD_BUTTON' | translate }} | ||
</button> | ||
<button | ||
*ngIf="isPluginInstalled(selectedPluginItem.name)" | ||
class="app-button active-destructive" | ||
(click)="onRemovePlugin(selectedPluginItem.name)" | ||
> | ||
<app-icon name="x-circle"></app-icon> | ||
{{ 'PLUGIN_REMOVE_BUTTON' | translate }} | ||
</button> | ||
<button | ||
*ngIf="shouldRestart" | ||
class="app-button" | ||
(click)="onRestartApp()" | ||
> | ||
{{ 'RESTART_TEXT' | translate }} | ||
</button> | ||
</div> | ||
<div | ||
markdown | ||
class="plugin-manager__item-details-summary" | ||
[data]="selectedPluginItem.summary" | ||
></div> | ||
</ng-container> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</ng-template> | ||
|
||
<ng-template #modalFooter> | ||
<div class="app-dialog-footer"> | ||
<button class="app-button active-primary right" (click)="toggleDialogChange.next(false);">{{ 'SAVE_BUTTON' | translate }}</button> | ||
</div> | ||
</ng-template> | ||
</nz-modal> |
42 changes: 42 additions & 0 deletions
42
src/app/components/plugin-manager/plugin-manager.component.spec.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,42 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { PluginManagerComponent } from './plugin-manager.component'; | ||
import { SharedModule } from 'app/modules/shared/shared.module'; | ||
import { PluginRegistryService } from 'app/services'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { PluginPropsFactory } from 'app/services/plugin/plugin-props-factory'; | ||
|
||
describe('PluginManagerComponent', () => { | ||
let component: PluginManagerComponent; | ||
let fixture: ComponentFixture<PluginManagerComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
PluginRegistryService, | ||
{ | ||
provide: PluginPropsFactory, | ||
use: { | ||
getPluginProps() {}, | ||
} | ||
} | ||
], | ||
imports: [ | ||
HttpClientModule, | ||
SharedModule, | ||
], | ||
declarations: [ PluginManagerComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(PluginManagerComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
89 changes: 89 additions & 0 deletions
89
src/app/components/plugin-manager/plugin-manager.component.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,89 @@ | ||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; | ||
import { PluginRegistryService } from 'app/services'; | ||
import { Observable, of } from 'rxjs'; | ||
import { catchError, map } from 'rxjs/operators'; | ||
|
||
import * as fromSettings from '../../reducers/settings/settings'; | ||
|
||
@Component({ | ||
selector: 'app-plugin-manager', | ||
templateUrl: './plugin-manager.component.html', | ||
styles: [] | ||
}) | ||
export class PluginManagerComponent implements OnInit { | ||
|
||
@Input() showPluginManager = false; | ||
@Input() settings: fromSettings.State; | ||
|
||
@Output() toggleDialogChange = new EventEmitter(); | ||
@Output() settingsJsonChange = new EventEmitter(); | ||
|
||
remotePlugins$: Observable<[]>; | ||
selectedPluginItem: any; | ||
|
||
shouldRestart = false; | ||
|
||
constructor( | ||
private pluginRegistry: PluginRegistryService, | ||
) { | ||
this.remotePlugins$ = this.pluginRegistry.getRemotePluginList().pipe( | ||
catchError((error) => { | ||
return of(null); | ||
}), | ||
map((data: any) => { | ||
if (data) { | ||
return data.items; | ||
} | ||
}) | ||
); | ||
} | ||
|
||
ngOnInit() { | ||
} | ||
|
||
onSelectPlugin(pluginItem: any) { | ||
this.selectedPluginItem = pluginItem; | ||
} | ||
|
||
isPluginInstalled(pluginName: string) { | ||
if (this.settings['plugin.list']) { | ||
return this.settings['plugin.list'].some(item => { | ||
const pluginInfo = this.pluginRegistry.getPluginInfoFromString(item); | ||
if (pluginInfo) { | ||
return pluginInfo.name === pluginName; | ||
} | ||
return false; | ||
}); | ||
} | ||
return false; | ||
} | ||
|
||
onAddPlugin(pluginName: string) { | ||
const settings: fromSettings.State = JSON.parse(JSON.stringify(this.settings)); | ||
settings['plugin.list'] = settings['plugin.list'] || []; | ||
settings['plugin.list'].push(pluginName); | ||
|
||
this.settingsJsonChange.next(JSON.stringify(settings)); | ||
this.shouldRestart = true; | ||
} | ||
onRemovePlugin(pluginName: string) { | ||
const settings: fromSettings.State = JSON.parse(JSON.stringify(this.settings)); | ||
settings['plugin.list'] = (settings['plugin.list'] || []).filter(pluginStr => { | ||
const pluginInfo = this.pluginRegistry.getPluginInfoFromString(pluginStr); | ||
if (pluginInfo) { | ||
return pluginName !== pluginInfo.name; | ||
} | ||
}); | ||
|
||
this.settingsJsonChange.next(JSON.stringify(settings)); | ||
this.shouldRestart = true; | ||
} | ||
|
||
onRestartApp() { | ||
location.reload(); | ||
} | ||
|
||
trackByName(index: number, item: any) { | ||
return item.name; | ||
} | ||
} |
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
Oops, something went wrong.