[angular-16-irish-monitor | DONE | CHANGED] update log Service, add log actions in claims and orcid links

This commit is contained in:
argirok 2023-12-14 14:01:06 +02:00
parent e4ae0ca35c
commit 5060151e09
5 changed files with 37 additions and 14 deletions

View File

@ -16,6 +16,7 @@ import {
import {UserManagementService} from "../../../services/user-management.service";
import {Subscriber, timer} from "rxjs";
import {map} from "rxjs/operators";
import {LogService} from "../../../utils/log/log.service";
@Component({
selector: 'claim-insert',
@ -59,7 +60,7 @@ import {map} from "rxjs/operators";
})
export class ClaimInsertComponent {
constructor(private claimService: ClaimsService, private _router: Router, private route: ActivatedRoute,
private userManagementService: UserManagementService) {
private userManagementService: UserManagementService, private _logService: LogService) {
}
subscriptions = [];
ngOnDestroy() {
@ -127,6 +128,7 @@ export class ClaimInsertComponent {
public feedRecordsJob;
public claims2Insert;
public records2Insert
infoToLog = [];
public insert() {
this.confirmOpen();
}
@ -145,6 +147,7 @@ export class ClaimInsertComponent {
this.errorInClaims = [];
this.insertedRecords = [];
this.errorInRecords = [];
this.infoToLog = [];
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
if (!user) {
this.saveAndNavigate();
@ -190,10 +193,11 @@ export class ClaimInsertComponent {
} else if (entity.project) {
claims.push(ClaimInsertComponent.createProjectClaim(result, entity, user.email, dashboard));
}
this.infoToLog.push([ result.title?result.title: result.id, entity.title?entity.title:entity.id]);
}
if (this.inlineEntity) {
this.infoToLog.push([ this.inlineEntity.title?this.inlineEntity.title: this.inlineEntity.id, entity.title?entity.title:entity.id]);
if (this.inlineEntity.result) {
if (entity.result) {
@ -256,6 +260,12 @@ export class ClaimInsertComponent {
data => {
this.claims2Insert = claims.length;
this.claimsJob = data.data;
if(this.properties.logServiceUrl) {
for(let info of this.infoToLog) {
this.subscriptions.push(this._logService.logLink(this.properties, info[0],info[1]).subscribe(res => {
}));
}
}
this.saveLocalStorage();
let timerSubscription = timer(0, 10000).pipe(
map(() => {
@ -375,7 +385,7 @@ export class ClaimInsertComponent {
localStorage.removeItem(this.localStoragePrefix + "claimsJob");
localStorage.removeItem(this.localStoragePrefix + "feedRecordsJob");
this._router.navigate(['/myclaims'], {queryParams: this.params});
this._router.navigate([this.properties.myClaimsLink], {queryParams: this.params});
}
}

View File

@ -6,10 +6,11 @@ import {LoadingModalModule} from '../../../utils/modal/loadingModal.module';
import {ClaimInsertComponent} from './insertClaim.component';
import {ClaimServiceModule} from '../../claim-utils/service/claimsService.module';
import {IconsModule} from "../../../utils/icons/icons.module";
import {LogServiceModule} from "../../../utils/log/LogService.module";
@NgModule({
imports: [
SharedModule, AlertModalModule, LoadingModalModule, ClaimServiceModule, IconsModule
SharedModule, AlertModalModule, LoadingModalModule, ClaimServiceModule, IconsModule, LogServiceModule
],
declarations: [ClaimInsertComponent],
exports:[ ClaimInsertComponent]

View File

@ -12,6 +12,7 @@ import {EnvProperties} from "../utils/properties/env-properties";
import {UserManagementService} from "../services/user-management.service";
import {OpenaireEntities} from "../utils/properties/searchFields";
import {FullScreenModalComponent} from "../utils/modal/full-screen-modal/full-screen-modal.component";
import {LogService} from "../utils/log/log.service";
declare var UIkit: any;
@ -377,7 +378,7 @@ export class OrcidWorkComponent {
private _router: Router,
private orcidService: OrcidService,
private resultLandingService: ResultLandingService,
private userManagementService: UserManagementService) {
private userManagementService: UserManagementService, private _logService: LogService) {
if (typeof document !== 'undefined') {
this.tokenUrl = properties.orcidTokenURL
+ "client_id=" + properties.orcidClientId
@ -540,7 +541,9 @@ export class OrcidWorkComponent {
private saveWork() {
this.subscriptions.push(this.orcidService.saveWork(this.resultLandingInfo, this.pids).subscribe(
response => {
if(this.properties.logServiceUrl) {
this.subscriptions.push(this._logService.logOrcidLink(this.properties, "added", this.resultLandingInfo.title, this.resultLandingInfo.identifiers.get('doi')[0]).subscribe(res => { }));
}
// for testing only
// this.openGrantModal("Add work in your ORCID record");
// this.requestGrant = true;
@ -722,6 +725,9 @@ export class OrcidWorkComponent {
if (deletedPutCodes) {
for (let i = 0; i < deletedPutCodes.length; i++) {
let deletedPutCode = deletedPutCodes[i];
if(this.properties.logServiceUrl) {
this.subscriptions.push(this._logService.logRemoveOrcidLink(this.properties, deletedPutCode).subscribe(res => { }));
}
if (deletedPutCode == null) {
deletedAll = false;
} else {

View File

@ -16,11 +16,12 @@ import {IconsModule} from '../utils/icons/icons.module';
import {IconsService} from "../utils/icons/icons.service";
import {orcid_add, orcid_bin} from "../utils/icons/icons";
import {FullScreenModalModule} from "../utils/modal/full-screen-modal/full-screen-modal.module";
import {LogServiceModule} from "../utils/log/LogService.module";
@NgModule({
imports: [
CommonModule, RouterModule, AlertModalModule, LoadingModule, ResultLandingUtilsModule,
IconsModule, FullScreenModalModule
IconsModule, FullScreenModalModule, LogServiceModule
],
declarations: [
OrcidComponent,

View File

@ -4,7 +4,7 @@ import {Injectable} from "@angular/core";
import {Observable} from "rxjs";
export abstract class Log{
action:string;
action: "link" | "orcid-link" | "upload-dois";
message:string;
protected constructor(action, message){
this.action =action;
@ -13,16 +13,18 @@ export abstract class Log{
}
export class LinkLog extends Log{
constructor() {
super("linking","a user linked");
constructor(sourceTitle,targetTitle) {
super("link","a user linked the \"" +sourceTitle+"\" " + " to the \"" +targetTitle+"\" " );
}
}
export class OrcidLinkLog extends Log{
constructor( action:'added'|'removed', title: string, doi: string) {
super("orcid-claim","user with ORCID iD " + action + " research product \"" + title+ "\" (" + doi + ") " + (action == 'added'?'to':'from')
constructor( action:'added'|'removed', title: string, id: string) {
super("orcid-link","user with ORCID ID " + action + " research product "+ (title?"\"" + title+ "\"":"") + " (" + id + ") " + (action == 'added'?'to':'from')
+ " their ORCID record.");
}
}
export class UploadLog extends Log{
@ -39,12 +41,15 @@ export class LogService {
logUploadDOIs(properties: EnvProperties, dois:number){
return this.http.post(properties.logServiceUrl+"logAction", new UploadLog(dois) );
}
logLink(properties: EnvProperties){
return this.http.post(properties.logServiceUrl+"logAction", new LinkLog() );
logLink(properties: EnvProperties, sourceTitle,targetTitle){
return this.http.post(properties.logServiceUrl+"logAction", new LinkLog(sourceTitle, targetTitle) );
}
logOrcidLink(properties: EnvProperties, action:'added'|'removed', title: string, doi: string){
return this.http.post(properties.logServiceUrl+"logAction", new OrcidLinkLog(action, title, doi) );
}
logRemoveOrcidLink(properties: EnvProperties, code: string){
return this.http.post(properties.logServiceUrl+"logAction", new OrcidLinkLog('removed',null, code) );
}
getLogs(properties: EnvProperties):Observable<any>{
return this.http.get(properties.logServiceUrl+"log");
}