Public logs update view and methods
This commit is contained in:
parent
e9938bc61d
commit
278d3cf74f
72
server.ts
72
server.ts
|
@ -32,44 +32,24 @@ export function app(): express.Express {
|
||||||
// Example Express Rest API endpoints
|
// Example Express Rest API endpoints
|
||||||
// server.get('/api/**', (req, res) => { });
|
// server.get('/api/**', (req, res) => { });
|
||||||
// Serve static files from /browser
|
// Serve static files from /browser
|
||||||
server.get('/log/', (req, res) => {
|
|
||||||
res.status(200).json(getLogs(null));
|
|
||||||
});
|
|
||||||
server.get('/log/:id', (req, res) => {
|
|
||||||
res.status(200).json(getLogs(req.params['id']));
|
|
||||||
});
|
|
||||||
|
|
||||||
server.get('/logFiles', (req, res) => {
|
server.get('/public-logs/:year/:month', (req, res) => {
|
||||||
fs.readdir(properties.logFilesPath, (err, files) => {
|
let today = new Date();
|
||||||
res.status(200).json(files);
|
let filename = getFileName(req.params['year'], req.params['month'])
|
||||||
});
|
res.setHeader('content-disposition','attachment; filename='+filename);
|
||||||
|
let file = " ";
|
||||||
});
|
try {
|
||||||
|
file = readFileSync(properties.logFilesPath + filename, 'utf-8');
|
||||||
server.get('/prettyLog', (req, res) => {
|
}catch (e){}
|
||||||
res.status(200).send( getPrettyLogs(null));
|
res.status(200).send( file);
|
||||||
});
|
|
||||||
server.get('/prettyLog/:id', (req, res) => {
|
|
||||||
res.status(200).send( getPrettyLogs(req.params['id']));
|
|
||||||
});
|
});
|
||||||
server.post('/logAction', jsonParser,(req, res) => {
|
server.post('/logAction', jsonParser,(req, res) => {
|
||||||
let log = req.body;
|
let log = req.body;
|
||||||
log.date = new Date();
|
log.date = new Date();
|
||||||
fs.appendFile(properties.logFilesPath + 'actions.log', JSON.stringify(log)+ ",\n", 'utf8', function(err) {
|
let filename = getFileName(log.date.getFullYear(), log.date.getMonth()+1);
|
||||||
if (err) {
|
fs.appendFile(properties.logFilesPath + filename, formatPrettyLog(log)+ "\n", 'utf8', function(err) {
|
||||||
return console.error(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
res.status(200).send({
|
|
||||||
code: 200,
|
|
||||||
message: 'action received!'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
server.get('/testLogAction', jsonParser,(req, res) => {
|
|
||||||
let log = {message:"log", date: new Date()};
|
|
||||||
fs.appendFile(properties.logFilesPath + 'actions.log', JSON.stringify(log)+ ",\n", 'utf8', function(err) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
return console.error(err);
|
return console.error(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -114,18 +94,12 @@ function run(): void {
|
||||||
console.log(`Node Express server listening on http://localhost:${port}`);
|
console.log(`Node Express server listening on http://localhost:${port}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getLogs(id){
|
|
||||||
const file = readFileSync(properties.logFilesPath + 'actions.log' + (id?"."+id:""), 'utf-8');
|
function getFileName(year, month){
|
||||||
return JSON.parse("[" + file.substring(0,file.length - 2) + "]");
|
return 'actions' + (year && month ? "_" + year + "_" + month : "")+".log";
|
||||||
}
|
}
|
||||||
function getPrettyLogs(id){
|
function formatPrettyLog(log){
|
||||||
const file = readFileSync(properties.logFilesPath + 'actions.log'+ (id?"."+id:""), 'utf-8');
|
return "On " + (log.date ? formatDateAndTime(log.date) : "") + " " /*+ logs[i].action + " "*/ + log.message + "<br>";
|
||||||
let logs = JSON.parse("[" + file.substring(0,file.length - 2) + "]");
|
|
||||||
let prettyLog = "";
|
|
||||||
for(let i = logs.length -1; i>=0; i--) {
|
|
||||||
prettyLog += "On " + (logs[i].date ? formatDateAndTime(logs[i].date) : "") + " " /*+ logs[i].action + " "*/ + logs[i].message + "<br>";
|
|
||||||
}
|
|
||||||
return prettyLog + getPrevNextLog(id?id:0);
|
|
||||||
}
|
}
|
||||||
function formatDateAndTime(dateStr){
|
function formatDateAndTime(dateStr){
|
||||||
let date = new Date(dateStr);
|
let date = new Date(dateStr);
|
||||||
|
@ -139,18 +113,6 @@ function formatDateAndTime(dateStr){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPrevNextLog(id= 0){
|
|
||||||
const files = fs.readdirSync(properties.logFilesPath);
|
|
||||||
let id_next:number = +id+1;
|
|
||||||
let id_prev:number = id-1;
|
|
||||||
let prev = (id>1 && files.indexOf("actions.log."+id_prev )!=-1)? '<a style="margin-left: 5px;" href="'+properties.logServiceUrl +
|
|
||||||
'prettyLog/' + id_prev + '">Prev</a>':"";
|
|
||||||
prev = (id ==1 && files.indexOf("actions.log")!=-1)? '<a style="margin-left: 5px;" href="'+properties.logServiceUrl +
|
|
||||||
'prettyLog">Prev</a>':prev;
|
|
||||||
let next = (id>=0 && files.indexOf("actions.log."+ id_next )!=-1)? ('<a style="margin-left: 5px;" href="'+properties.logServiceUrl +'prettyLog/' +id_next + '">Next</a>'):"";
|
|
||||||
return "<br>" + prev + next;
|
|
||||||
|
|
||||||
}
|
|
||||||
// Webpack will replace 'require' with '__webpack_require__'
|
// Webpack will replace 'require' with '__webpack_require__'
|
||||||
// '__non_webpack_require__' is a proxy to Node 'require'
|
// '__non_webpack_require__' is a proxy to Node 'require'
|
||||||
// The below code is to ensure that the server is run only when not requiring the bundle.
|
// The below code is to ensure that the server is run only when not requiring the bundle.
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
import {NgModule} from "@angular/core";
|
|
||||||
import {RouterModule} from "@angular/router";
|
|
||||||
import {PublicLogsComponent} from "./public-logs.component";
|
|
||||||
|
|
||||||
@NgModule({
|
|
||||||
imports: [
|
|
||||||
RouterModule.forChild([
|
|
||||||
{
|
|
||||||
path: '',
|
|
||||||
component: PublicLogsComponent
|
|
||||||
}
|
|
||||||
])
|
|
||||||
]
|
|
||||||
})
|
|
||||||
export class PublicLogsRoutingModule {
|
|
||||||
}
|
|
|
@ -13,49 +13,57 @@ import {CookieLawService} from "../openaireLibrary/sharedComponents/cookie-law/c
|
||||||
template: `
|
template: `
|
||||||
<div class="uk-container uk-container-large uk-margin-top">
|
<div class="uk-container uk-container-large uk-margin-top">
|
||||||
<h3>Public logs</h3>
|
<h3>Public logs</h3>
|
||||||
<ng-container *ngIf="!isConsent">
|
|
||||||
<ul class="uk-tab " uk-switcher>
|
<ul class="uk-tab " uk-switcher>
|
||||||
<li><a href="#">Linking</a></li>
|
<li><a href="#">Dashboard</a></li>
|
||||||
|
<!-- <li><a href="#">Linking</a></li>
|
||||||
<li><a href="#">ORCID Claim</a></li>
|
<li><a href="#">ORCID Claim</a></li>
|
||||||
<li><a href="#">Upload DOIs</a></li>
|
<li><a href="#">Upload DOIs</a></li>-->
|
||||||
<li><a href="#">OpenOrgs</a></li>
|
<li><a href="#">OpenOrgs</a></li>
|
||||||
<li><a href="#"> Web stats from Matomo</a></li>
|
<li><a href="#"> Web stats from Matomo</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="uk-switcher uk-margin">
|
<ul class="uk-switcher uk-margin">
|
||||||
<li>
|
<li>
|
||||||
<ng-container *ngTemplateOutlet="formattedLogs; context: { logs: claimsLogs}"></ng-container>
|
|
||||||
<a [href]="properties.logServiceUrl + 'prettyLog'" target="_blank">View all logs</a> <a [href]="properties.logServiceUrl + 'log'" target="_blank">[json]</a>
|
<!-- <ng-container *ngTemplateOutlet="formattedLogs; context: { logs: claimsLogs}"></ng-container>-->
|
||||||
|
<div>
|
||||||
|
|
||||||
|
National Open Access Monitor - Ireland, creates public logs when users uploas dois, claim links to research outputs or claim a research output to their ORCID profile.<br>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div>Get monthly logs for Dashboard:</div>
|
||||||
|
|
||||||
|
<ul class="uk-list">
|
||||||
|
<ng-container *ngFor="let year of years ">
|
||||||
|
<ng-container *ngFor="let month of months ">
|
||||||
|
<ng-container *ngIf="(year == today.getFullYear() && month <= today.getMonth()+1 && month >= startDate.getMonth()+1) || (year >startDate.getFullYear() || year < today.getFullYear()) ">
|
||||||
|
<li>
|
||||||
|
<a [href]="properties.logServiceUrl + 'public-logs/' + year + '/' + month " target="_blank"> {{month}}/{{year}}</a>
|
||||||
|
</li>
|
||||||
|
</ng-container>
|
||||||
|
</ng-container>
|
||||||
|
</ng-container>
|
||||||
|
</ul> </li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<div>Get monthly logs for OpenOrgs:</div>
|
||||||
|
<ul class="uk-list">
|
||||||
|
<ng-container *ngFor="let year of years ">
|
||||||
|
<ng-container *ngFor="let month of months ">
|
||||||
|
<ng-container *ngIf="(year == today.getFullYear() && month <= today.getMonth()+1 && month >= startDate.getMonth()+1) || (year >startDate.getFullYear() || year < today.getFullYear()) "> <li>
|
||||||
|
<li>
|
||||||
|
<a [href]="properties.openOrgsUrl + '/public-api/logs/' + year + '/' + month+ '/IE' " target="_blank"> {{month}}/{{year}}</a>
|
||||||
|
</li>
|
||||||
|
</ng-container>
|
||||||
|
</ng-container>
|
||||||
|
</ng-container>
|
||||||
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<ng-container *ngTemplateOutlet="formattedLogs; context: { logs: orcidClaimsLogs}"></ng-container>
|
<div class="uk-alert uk-alert-warning">Coming soon!</div>
|
||||||
<a [href]="properties.logServiceUrl + 'prettyLog'" target="_blank">View all logs</a> <a [href]="properties.logServiceUrl + 'log'" target="_blank">[json]</a>
|
<!-- <a target="_blank" href="https://beta.analytics.openaire.eu/index.php?apiAction=get&apiModule=API&date=2022-01-01,2023-12-31&expanded=1&filter_limit=-1&force_api_session=1&format=JSON&format_metrics=1&idSite=407&method=API.getProcessedReport&module=API&period=month&token_auth=anonymous"> View Matomo logs</a>-->
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<ng-container *ngTemplateOutlet="formattedLogs; context: { logs: uploadDoisLogs}"></ng-container>
|
|
||||||
<a [href]="properties.logServiceUrl + 'prettyLog'" target="_blank">View all logs</a> <a [href]="properties.logServiceUrl + 'log'" target="_blank">[json]</a>
|
|
||||||
</li>
|
|
||||||
<li>Bazinga!
|
|
||||||
<br>
|
|
||||||
<a href="https://beta.orgs.openaire.eu/public-api/logs/IE/0/50" target="_blank"> View OpenOrgs logs</a>
|
|
||||||
</li>
|
|
||||||
<li>Bazinga!
|
|
||||||
<br>
|
|
||||||
<a target="_blank" href="https://beta.analytics.openaire.eu/index.php?apiAction=get&apiModule=API&date=2022-01-01,2023-12-31&expanded=1&filter_limit=-1&force_api_session=1&format=JSON&format_metrics=1&idSite=407&method=API.getProcessedReport&module=API&period=month&token_auth=anonymous"> View Matomo logs</a>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</ng-container>
|
|
||||||
<ng-container *ngIf="isConsent">
|
|
||||||
<div class="uk-alert uk-alert-warning">
|
|
||||||
National Open Access Monitor - Ireland, creates public logs for user actions.<br>
|
|
||||||
By using the National Open Access Monitor - Ireland portal you consent to log your actions <a
|
|
||||||
routerLink="/public-logs"> View Public logs <span class="uk-icon">
|
|
||||||
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
|
|
||||||
ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
|
|
||||||
points="7 4 13 10 7 16"></polyline></svg>
|
|
||||||
</span></a>
|
|
||||||
<button class="uk-button uk-button-primary" (click)="redirect()">Proceed</button>
|
|
||||||
</div>
|
|
||||||
</ng-container>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<ng-template #formattedLogs let-logs="logs">
|
<ng-template #formattedLogs let-logs="logs">
|
||||||
|
@ -70,12 +78,12 @@ import {CookieLawService} from "../openaireLibrary/sharedComponents/cookie-law/c
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class PublicLogsComponent extends BaseComponent implements OnInit {
|
export class PublicLogsComponent extends BaseComponent implements OnInit {
|
||||||
allLogs;
|
|
||||||
uploadDoisLogs;
|
|
||||||
claimsLogs;
|
|
||||||
orcidClaimsLogs;
|
|
||||||
isConsent = false;
|
isConsent = false;
|
||||||
redirectUrl = null;
|
redirectUrl = null;
|
||||||
|
startDate = new Date();
|
||||||
|
today = new Date();
|
||||||
|
months = [];
|
||||||
|
years = [];
|
||||||
constructor(protected _router: Router,
|
constructor(protected _router: Router,
|
||||||
protected _route: ActivatedRoute,
|
protected _route: ActivatedRoute,
|
||||||
protected seoService: SEOService,
|
protected seoService: SEOService,
|
||||||
|
@ -85,48 +93,14 @@ export class PublicLogsComponent extends BaseComponent implements OnInit {
|
||||||
private _logService:LogService,
|
private _logService:LogService,
|
||||||
private userManagementsService: UserManagementService, private cookieLawService: CookieLawService) {
|
private userManagementsService: UserManagementService, private cookieLawService: CookieLawService) {
|
||||||
super();
|
super();
|
||||||
|
this.startDate.setFullYear(2023,11,1)
|
||||||
|
this.months = Array.from({ length:12 }, (_, index) => 12 - index);
|
||||||
|
this.years = Array.from({ length:this.today.getFullYear() + 1 - this.startDate.getFullYear() }, (_, index) => this.today.getFullYear() - index);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.title = 'Public logs';
|
this.title = 'Public logs';
|
||||||
this.description = 'Public logs of user actions in OA monitor - Ireland';
|
this.description = 'Public logs of user actions in OA monitor - Ireland';
|
||||||
this.setMetadata();
|
this.setMetadata();
|
||||||
this.subscriptions.push(this._route.queryParams.subscribe(params => {
|
|
||||||
|
|
||||||
this.isConsent = params && params['redirectUrl'];
|
|
||||||
this.redirectUrl = params['redirectUrl'];
|
|
||||||
if(!this.isConsent){
|
|
||||||
this.subscriptions.push(this._logService.getLogs(this.properties).subscribe(logs => {
|
|
||||||
this.allLogs = logs.slice(logs.length -10 ,logs.length);
|
|
||||||
this.uploadDoisLogs = [];
|
|
||||||
this.claimsLogs = [];
|
|
||||||
this.orcidClaimsLogs = [];
|
|
||||||
for(let i=logs.length; i--; i==0){
|
|
||||||
let log = logs[i];
|
|
||||||
log.date = new Date(log.date);
|
|
||||||
|
|
||||||
if(log.action == 'upload-dois' && this.uploadDoisLogs.length <10){
|
|
||||||
this.uploadDoisLogs.push(log);
|
|
||||||
}else if(log.action == 'link' && this.claimsLogs.length <10){
|
|
||||||
this.claimsLogs.push(log);
|
|
||||||
} else if(log.action == 'orcid-link' && this.orcidClaimsLogs.length <10){
|
|
||||||
this.orcidClaimsLogs.push(log);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect() {
|
|
||||||
//if parameters are not read yet, force them to use the function parameter
|
|
||||||
this.cookieLawService.storeCookie("logActions-NOAMIreland")
|
|
||||||
if (this.redirectUrl && this.redirectUrl != "") {
|
|
||||||
this.redirectUrl = decodeURIComponent(this.redirectUrl);
|
|
||||||
this.userManagementsService.setRedirectUrl(this.redirectUrl);
|
|
||||||
this._router.navigate(['/reload']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
import {NgModule} from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
import {CommonModule} from '@angular/common';
|
import {CommonModule} from '@angular/common';
|
||||||
import {PublicLogsComponent} from "./public-logs.component";
|
import {PublicLogsComponent} from "./public-logs.component";
|
||||||
import {PublicLogsRoutingModule} from "./public-logs-routing.module";
|
|
||||||
import {LogServiceModule} from "../openaireLibrary/utils/log/LogService.module";
|
import {LogServiceModule} from "../openaireLibrary/utils/log/LogService.module";
|
||||||
import {RouterModule} from "@angular/router";
|
import {Route, RouterModule} from "@angular/router";
|
||||||
|
|
||||||
|
const routes: Route[] = [
|
||||||
|
{
|
||||||
|
path: '', component: PublicLogsComponent
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [PublicLogsComponent],
|
declarations: [PublicLogsComponent],
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule, PublicLogsRoutingModule, LogServiceModule, RouterModule
|
CommonModule, RouterModule.forChild(routes), LogServiceModule, RouterModule
|
||||||
],
|
],
|
||||||
exports: [PublicLogsComponent]
|
exports: [PublicLogsComponent]
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue