[develop | DONE | ADDED ] ADD clear cache component in plugins for admins

This commit is contained in:
argirok 2024-11-04 10:46:46 +02:00
parent 236522145c
commit 8083e7a531
4 changed files with 73 additions and 4 deletions

View File

@ -68,6 +68,7 @@
class="uk-card uk-card-default uk-padding-large uk-text-center uk-margin-bottom uk-text-bold">
<div>No plugins found</div>
</div>
<clear-cache *ngIf="clearCacheRequests && showClearCache()" [requests]="clearCacheRequests"></clear-cache>
<ng-container *ngFor="let placement of pluginUtils.placementsOptions">
<ng-container *ngIf="selectedPlacementView == placement.value || selectedPlacementView == 'all'">

View File

@ -1,7 +1,7 @@
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {HelpContentService} from "../../services/help-content.service";
import {FormArray, UntypedFormArray, UntypedFormBuilder, UntypedFormGroup, ValidatorFn} from "@angular/forms";
import {UntypedFormBuilder, ValidatorFn} from "@angular/forms";
import {Page} from "../../utils/entities/adminTool/page";
import {EnvProperties} from '../../utils/properties/env-properties';
import {HelperFunctions} from "../../utils/HelperFunctions.class";
@ -21,6 +21,8 @@ import {PluginUtils} from "./utils/pluginUtils";
import {CommunityService} from "../../connect/community/community.service";
import {CommunityInfo} from "../../connect/community/communityInfo";
import {AlertModal} from "../../utils/modal/alert";
import {Session} from "../../login/utils/helper.class";
import {UserManagementService} from "../../services/user-management.service";
@Component({
selector: 'plugins',
@ -62,12 +64,13 @@ export class PluginsComponent implements OnInit {
// editSubmenuOpen = false;
filterActive = false;
@ViewChild('deleteModal') deleteModal: AlertModal;
clearCacheRequests = [];
user;
constructor(private element: ElementRef, private route: ActivatedRoute, private _router: Router,
private communityService: CommunityService,
private title: Title, private _helpContentService: HelpContentService,
private _pluginsService: PluginsService, private _fb: UntypedFormBuilder,
private _clearCacheService: ClearCacheService) {
private _clearCacheService: ClearCacheService, private _userManagementService:UserManagementService) {
}
ngOnInit() {
@ -76,11 +79,24 @@ export class PluginsComponent implements OnInit {
community => {
this.communityInfo = community;
}));
this.subscriptions.push(this._userManagementService.getUserInfo().subscribe( user =>{
this.user = user;
}))
this.subscriptions.push(this.route.params.subscribe(params => {
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
this.selectedCommunityPid = params.community;
//initiate requests for clear cache prompt
this.clearCacheRequests = [];
if (properties.deleteBrowserCacheUrl) {
this.clearCacheRequests.push(properties.deleteBrowserCacheUrl + "/" + this.selectedCommunityPid)
}
if (this.properties.deleteCacheUrl) {
this.clearCacheRequests.push(properties.deleteCacheUrl + "?url=" + encodeURIComponent(properties.utilsService +
"/portals/countResults?field=communityId&value=" + encodeURIComponent(this.selectedCommunityPid)));
}
console.log(this.clearCacheRequests)
this.subscriptions.push(this.route.queryParams.subscribe(params => {
HelperFunctions.scroll();
this.selectedPageId = params['pageId'];
@ -370,4 +386,8 @@ export class PluginsComponent implements OnInit {
));
this.showLoading = false;
}
showClearCache(){
return this.user && (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user));
}
}

View File

@ -27,6 +27,7 @@ import {PluginWrapperModule} from "./wrapper/plugin-wrapper.module";
import {SideBarModule} from "../sharedComponents/sidebar/sideBar.module";
import {PluginEditWrapperModule} from "./wrapper/plugin-edit-wrapper.module";
import {TransitionGroupModule} from "../../utils/transition-group/transition-group.module";
import {ClearCacheComponent} from "../sharedComponents/clearCache.component";
@NgModule({
@ -34,7 +35,7 @@ import {TransitionGroupModule} from "../../utils/transition-group/transition-gro
CommonModule, RouterModule, FormsModule,
AlertModalModule, ReactiveFormsModule, AdminToolServiceModule, InputModule, MatAutocompleteModule, MatFormFieldModule, MatChipsModule,
MatCheckboxModule, AdminTabsModule, PageContentModule, PluginsRoutingModule, SearchInputModule, IconsModule, LoadingModule, CKEditorModule,
MatSlideToggleModule, PluginWrapperModule, SideBarModule, PluginEditWrapperModule, TransitionGroupModule
MatSlideToggleModule, PluginWrapperModule, SideBarModule, PluginEditWrapperModule, TransitionGroupModule, ClearCacheComponent
],
providers:[PluginsService],
declarations: [PluginsComponent],

View File

@ -0,0 +1,47 @@
import {Component, Input, ViewChild} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {AlertModal} from "../../utils/modal/alert";
import {AlertModalModule} from "../../utils/modal/alertModal.module";
import {CommonModule} from "@angular/common";
@Component({
standalone: true,
selector: 'clear-cache',
imports: [AlertModalModule, CommonModule],
template: `
<ng-container *ngIf="requests && requests.length > 0">
<div class="uk-alert uk-padding-xsmall uk-text-small uk-text-center">
Made changes but can't see them?
<a (click)="promtToClear()">Try to clear the cache</a> to resolve the issue.
</div>
<modal-alert #deleteCacheModal [overflowBody]="false" (alertOutput)="clear()"
classTitle="uk-background-primary uk-light"></modal-alert>
</ng-container>
`,
})
export class ClearCacheComponent {
@Input() requests:string[] ;
@ViewChild('deleteCacheModal') deleteCacheModal: AlertModal;
constructor(private http: HttpClient ) {
}
promtToClear(){
this.deleteCacheModal.alertTitle = 'Confirm Cache Clear';
this.deleteCacheModal.message = 'Are you sure you want to clear the service cache?';
this.deleteCacheModal.okButtonText = 'Yes';
this.deleteCacheModal.open();
}
clear(){
for( let request of this.requests){
this.http.get(request).subscribe( res => {
console.log( res);
});
}
}
}