Skip to content

Commit

Permalink
SessionStorage => LocalStorage
Browse files Browse the repository at this point in the history
commit 76426e4
Author: Juanjo Ortilles <[email protected]>
Date:   Fri Jun 21 07:51:00 2024 +0200

    Cambio de sessionStorage => LocalStorage (Vigilar mailing)
  • Loading branch information
jortilles committed Jun 28, 2024
1 parent d467367 commit f6be6f4
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class MailDashboardsController {

await page.goto(`${serverConfig.server_baseURL}`)
await page.evaluate((res) => {
sessionStorage.setItem('token', res.token);
sessionStorage.setItem('user', JSON.stringify(res.user));
sessionStorage.setItem('id', res.user._id)
localStorage.setItem('token', res.token);
localStorage.setItem('user', JSON.stringify(res.user));
localStorage.setItem('id', res.user._id)
}, res);


Expand Down
2 changes: 1 addition & 1 deletion eda/eda_app/src/app/core/pages/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class LoginComponent implements OnInit {
// this.urlParams = this.route.snapshot.queryParams['params'];
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/home';

this.email = sessionStorage.getItem('email') || '';
this.email = localStorage.getItem('email') || '';

if (this.email.length > 1) {
this.remember = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class EdaBlankPanelComponent implements OnInit {
}

getEditMode() {
const user = sessionStorage.getItem('user');
const user = localStorage.getItem('user');
const userName = JSON.parse(user).name;
return (userName !== 'edaanonim' && !this.inject.isObserver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,14 @@ export class LinkDashboardsComponent extends EdaDialogAbstract {

if (!this.controller.params.modeSQL) {
res.dashboard.config.filters.forEach(filter => {

if (filter.column.value.column_name === column.col && filter.table.value === column.table) {
disable = false;
if(filter.column){
if (filter.column.value.column_name === column.col && filter.table.value === column.table) {
disable = false;
}
}else{
console.log('NO SE HA IMPLEMENTADO TODAVÍA INFORMES VINCULADOS CON EL MODO ARBOL.');
console.log(res.dashboard.config.title);
}

this.targetColumn = column.col;
this.targetTable = column.table;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class EdaTitlePanelComponent implements OnInit {
}

public setEditMode(): void {
const user = sessionStorage.getItem('user');
const user = localStorage.getItem('user');
const userName = JSON.parse(user).name;
this.display.editMode = (userName !== 'edaanonim' && !this.inject.isObserver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy {
this.initializeResponsiveSizes();
this.initializeGridsterOptions();
this.initializeForm();
let tags = JSON.parse(sessionStorage.getItem('tags'));
let tags = JSON.parse(localStorage.getItem('tags'));

if (tags) {
this.tags = _.uniqBy(tags, 'value');
Expand Down Expand Up @@ -553,7 +553,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy {
// Dashboard Panels
private initializePanels(): void {

const user = sessionStorage.getItem('user');
const user = localStorage.getItem('user');
const userID = JSON.parse(user)._id;

this.inject = {
Expand Down Expand Up @@ -607,7 +607,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy {

// Dashboard control
public async setEditMode() {
const user = sessionStorage.getItem('user');
const user = localStorage.getItem('user');
const userName = JSON.parse(user).name;
const userID = JSON.parse(user)._id;
this.display_v.edit_mode = (userName !== 'edaanonim') && !(this.grups.filter(group => group.name === 'EDA_RO' && group.users.includes(userID)).length !== 0)
Expand Down Expand Up @@ -1644,7 +1644,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy {
this.selectedTags.push(this.applyNewTag)
this.addTag = !this.addTag;
this.tags.push(tag)
sessionStorage.setItem('tags', JSON.stringify(this.tags));
localStorage.setItem('tags', JSON.stringify(this.tags));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ export class DataSourceDetailComponent implements OnInit, OnDestroy {
}
openNewViewDialog() {
this.viewController = new EdaDialogController({
params: { user: sessionStorage.getItem('user'), model_id: this.dataModelService.model_id },
params: { user: localStorage.getItem('user'), model_id: this.dataModelService.model_id },
close: (event, response) => {
if (!_.isEqual(event, EdaDialogCloseEvent.NONE)) {
this.dataModelService.addView(response);
Expand Down
8 changes: 4 additions & 4 deletions eda/eda_app/src/app/module/pages/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class HomeComponent implements OnInit {
private setIsObserver = async () => {
this.groupService.getGroupsByUser().subscribe(
res => {
const user = sessionStorage.getItem('user');
const user = localStorage.getItem('user');
const userID = JSON.parse(user)._id;
this.grups = res;
this.isObserver = this.grups.filter(group => group.name === 'EDA_RO' && group.users.includes(userID)).length !== 0
Expand All @@ -78,7 +78,7 @@ export class HomeComponent implements OnInit {
}

private ifAnonymousGetOut(): void {
const user = sessionStorage.getItem('user');
const user = localStorage.getItem('user');
const userName = JSON.parse(user).name;

if (userName === 'edaanonim' || userName === 'EDA_RO') {
Expand Down Expand Up @@ -128,7 +128,7 @@ export class HomeComponent implements OnInit {
}
}
this.tags = _.uniqBy(this.tags, 'value'); //treiem repetits
sessionStorage.setItem('tags', JSON.stringify(this.tags)); //IMPORTANT, guardem tags per sessió! Els recuperem a cada dashboard
localStorage.setItem('tags', JSON.stringify(this.tags)); //IMPORTANT, guardem tags per sessió! Els recuperem a cada dashboard
this.filterDashboards({ label: this.AllTags, value: 1 });
this.setIsObserver();
} catch (err) {
Expand Down Expand Up @@ -227,7 +227,7 @@ export class HomeComponent implements OnInit {
result = this.isAdmin ;
if (result == false) {
if (dashboard.config.onlyIcanEdit === true) {
if ( sessionStorage.getItem('user') == dashboard.user) {
if ( localStorage.getItem('user') == dashboard.user) {
result = true;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class UsersFitxaComponent extends EdaDialogAbstract {

this.form.get('role').setValue(rolesNames);

this.iam = user.email === JSON.parse(sessionStorage.getItem('user')).email;
this.iam = user.email === JSON.parse(localStorage.getItem('user')).email;
}, err => this.alertService.addError(err)
);
}
Expand Down
2 changes: 1 addition & 1 deletion eda/eda_app/src/app/services/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ApiService {
}

private getSearchParamToken() {
const token = sessionStorage.getItem('token');
const token = localStorage.getItem('token');
let params: HttpParams = new HttpParams();

if (token) {
Expand Down
28 changes: 14 additions & 14 deletions eda/eda_app/src/app/services/api/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export class UserService extends ApiService {

/** Save User and Token in localstorage */
savingStorage(id: string, token: string, user: User) {
sessionStorage.setItem('id', id);
sessionStorage.setItem('token', token);
sessionStorage.setItem('user', JSON.stringify(user));
localStorage.setItem('id', id);
localStorage.setItem('token', token);
localStorage.setItem('user', JSON.stringify(user));

this.user = user;
this.token = token;
Expand All @@ -104,9 +104,9 @@ export class UserService extends ApiService {
/** Login user into app */
login(user: User, remember: boolean): Observable<any> {
if (remember) {
sessionStorage.setItem('email', user.email);
localStorage.setItem('email', user.email);
} else {
sessionStorage.removeItem('email');
localStorage.removeItem('email');
}

return this.post(`${this.route}/login`, user, true)
Expand All @@ -133,7 +133,7 @@ export class UserService extends ApiService {
return this.get( `${this.route}/refresh-token` )
.pipe(map((res: any) => {
this.token = res.token;
sessionStorage.setItem('token', this.token);
localStorage.setItem('token', this.token);

return true;
})
Expand All @@ -152,9 +152,9 @@ export class UserService extends ApiService {

/** Load items localstorage */
loadStorage() {
if (sessionStorage.getItem('token')) {
this.token = sessionStorage.getItem('token');
this.user = JSON.parse(sessionStorage.getItem('user'));
if (localStorage.getItem('token')) {
this.token = localStorage.getItem('token');
this.user = JSON.parse(localStorage.getItem('user'));

this.getIsAdminUser(this.user._id).subscribe(
(value: any) => this.isAdmin = value.isAdmin,
Expand All @@ -175,16 +175,16 @@ export class UserService extends ApiService {

/** Verify if user is logged */
isLogged() {
return this.token.length > 5 || !!sessionStorage.getItem('token');
return this.token.length > 5 || !!localStorage.getItem('token');
}

/** Logout user and clean localstorage */
logout() {
this.user = null;
this.token = '';

sessionStorage.removeItem('user');
sessionStorage.removeItem('token');
localStorage.removeItem('user');
localStorage.removeItem('token');

this.router.navigate(['/login']);
}
Expand All @@ -207,11 +207,11 @@ export class UserService extends ApiService {
}

getUserObject(){
return JSON.parse(sessionStorage.getItem('user'));
return JSON.parse(localStorage.getItem('user'));
}

getToken(){
return sessionStorage.getItem('token');
return localStorage.getItem('token');
}
}

2 changes: 1 addition & 1 deletion eda/eda_app/src/app/services/utils/file-utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as _ from 'lodash';
export class FileUtiles {

connection(route: string, getParams?: {}) {
let url = `${URL_SERVICES}${route}?token=${sessionStorage.getItem('token')}`;
let url = `${URL_SERVICES}${route}?token=${localStorage.getItem('token')}`;
if (!_.isNil(getParams)) {
_.forEach(getParams, (value: any, key: any) => {
url += '&' + key + '=' + value;
Expand Down
4 changes: 2 additions & 2 deletions eda/eda_app/src/app/services/utils/query-builder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class QueryBuilderService extends ApiService {
id: '1',
model_id: params.dataSource,
user: {
user_id: sessionStorage.getItem('id'),
user_id: localStorage.getItem('id'),
user_roles: ['USER_ROLE']
},
dashboard: {
Expand Down Expand Up @@ -108,7 +108,7 @@ export class QueryBuilderService extends ApiService {
id: '1',
model_id: params.dataSource,
user: {
user_id: sessionStorage.getItem('id'),
user_id: localStorage.getItem('id'),
user_roles: ['USER_ROLE']
},
dashboard: {
Expand Down
6 changes: 3 additions & 3 deletions eda/eda_app/src/app/services/utils/settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export class SettingsService {
}

saveSettings() {
sessionStorage.setItem('settings', JSON.stringify(this.settings));
localStorage.setItem('settings', JSON.stringify(this.settings));
}

loadingSettings() {
if (sessionStorage.getItem('settings')) {
this.settings = JSON.parse(sessionStorage.getItem('settings'));
if (localStorage.getItem('settings')) {
this.settings = JSON.parse(localStorage.getItem('settings'));
this.applyTheme(this.settings.tema);
} else {
this.applyTheme(this.settings.tema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class SidebarComponent implements OnInit {
}

setEditMode(): void {
const user = sessionStorage.getItem('user');
const user = localStorage.getItem('user');
const userName = JSON.parse(user).name;
this.edit_mode = (userName !== 'edaanonim');
}
Expand Down

0 comments on commit f6be6f4

Please sign in to comment.