Commit bdfd0cc3 authored by Thomas Frion's avatar Thomas Frion

[UPDF] Use unit settings for map

* Now we can get all settings of a unit, just give the setting name
* The zoom for the map is the unit's setting

TODO:
	* Update left side bar when we open it
	* Refactor code of the component
	* Add picker to represent unit
	* Loader for login form
parent 29396548
import { Component, OnInit } from '@angular/core';
import * as L from 'leaflet';
import { Unit } from '../services/api/models/unit';
import { UnitSetting, UnitModel } from '../services/api/models/unit';
import { environment } from '../../environments/environment'
/**
......@@ -14,15 +14,19 @@ import { environment } from '../../environments/environment'
styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {
private map;
constructor() { }
ngOnInit(): void {
const unit : Unit = JSON.parse(localStorage.getItem(environment.localStorage.unit));
const unit : UnitModel = new UnitModel(
JSON.parse(localStorage.getItem(environment.localStorage.unit))
);
this.map = L.map('map', {
center: this.getCoor(unit.geom),
zoom: unit.settings[0].value
zoom: unit.getSetting(UnitSetting.SettingName.Zoom).value //unit.settings[0].value
});
const tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
......
......@@ -33,5 +33,40 @@ export interface Unit{
email: string,
geom: string,
dept: string,
settings: UnitSetting[]
settings: UnitSetting[],
}
export class UnitModel {
readonly id?: number;
code: string;
name: string;
email: string;
geom: string;
dept: string;
settings: UnitSetting[];
constructor(unit : Unit) {
this.id = unit.id;
this.code = unit.code;
this.name = unit.name;
this.email = unit.email;
this.geom = unit.geom;
this.dept = unit.dept;
this.settings = unit.settings;
}
public getSetting(name: string) : UnitSetting {
let i = 0;
let setting : UnitSetting = null;
while(i < this.settings.length && setting == null){
if(this.settings[i].name == name){
setting = this.settings[i];
}
i++;
}
return setting;
}
}
\ No newline at end of file
......@@ -86,7 +86,10 @@ export class AuthService {
* @returns true if we are connected false otherwise.
*/
loggedIn() : boolean {
return this.getActiveToken().access != null;
let token = this.getToken();
console.log(token);
return token != null;
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment