Commit bb80668d authored by Sebastian's avatar Sebastian

update / oauth - tags bearbeiten

parent 5355db1f
......@@ -280,12 +280,23 @@ export class OsmNode {
return undefined;
}
removeOsmTag(tag: KeyValuePair){
let idx=(this.osmtags.indexOf(tag,0));
removeOsmTag(tag: KeyValuePair|string){
let search = "";
if(tag instanceof KeyValuePair){
search=tag.key;
}else{
search=tag;
}
let idx=-1;
for(let i in this.tags){
if(this.osmtags[i].key == search){
idx=parseInt(i);
}
}
if(idx > -1){
this.osmtags.splice(idx,1);
}
}
addOsmTag(tag: KeyValuePair){
......@@ -303,6 +314,14 @@ export class OsmNode {
}
return false;
}
}
getOsmTag(key:string){
for(let tag of this.osmtags){
if(tag.key == key){
return tag;
}
}
return null;
}
getTag(key:string){
for(let tag of this.tags){
......@@ -332,6 +351,23 @@ export class OsmNode {
tag.source = source;
this.addTag(tag);
}
setOsmTag(key:string,value:string,displayName?:string,source?:string){
if(key == undefined || key == null || value == undefined || value == null){
return;
}
let tag = this.getOsmTag(key);
if(tag == null){
tag = new KeyValuePair({});
}else{
this.removeTag(tag);
}
tag.key = key;
tag.value = value;
tag.displayName = displayName;
tag.source = source;
this.addOsmTag(tag);
}
addTag(tag:KeyValuePair){
......@@ -582,7 +618,8 @@ export class OsmNode {
dimensions : new Array,
dataGroups : new Array,
lon: this.lon,
lat: this.lat
lat: this.lat,
osmTags: this.osmtags
};
for(let dg of this.dataGroups){
......
......@@ -16,12 +16,7 @@ import { KeyValuePair } from '../models/KeyValuePair';
providedIn: 'root'
})
/*
* Alan:
* größere abfrageblöcke in eigene private funktionen extrahiert
* getOsmTypeFromNode als "allgemeinere" loesung implementiert,
* da die vorherige loesung nur fuer 'way' und 'node' funktionierte
*/
export class GeoportalApiService {
httpOptions = {
......@@ -32,9 +27,6 @@ export class GeoportalApiService {
};
private apiURL = 'http://127.0.0.1:8080/geoportal';
private endpoints: GeoportalApiEndpoint[];
private defaultEndpoint: GeoportalApiEndpoint;
private bearer: string;
......@@ -45,46 +37,54 @@ export class GeoportalApiService {
*/
constructor(private logger: LogService, private http: HttpClient, private cache: CacheService) {
switch(window.location.hostname){
case 'localhost':{
this.apiURL = 'http://127.0.0.1:8080/geoportal';
break;
}
case 'geoportal.transformationsstadt.de':{
this.apiURL = 'https://geoportal.transformationsstadt.de:1443/geoportal';
break;
}
default:{
this.apiURL = 'https://entwicklungssystem.transformationsstadt.de:1443/geoportal';
break;
switch(window.location.hostname){
case 'localhost':{
this.apiURL = 'http://127.0.0.1:8080/geoportal';
break;
}
case 'geoportal.transformationsstadt.de':{
this.apiURL = 'https://geoportal.transformationsstadt.de:1443/geoportal';
break;
}
default:{
this.apiURL = 'https://entwicklungssystem.transformationsstadt.de:1443/geoportal';
break;
}
}
}
//private apiURL = 'https://geoportal.transformationsstadt.de:1443/geoportal';
this.defaultEndpoint = new GeoportalApiEndpoint('*', '*', this.defaultResponseHandler, this.defaultErrorHandler);
this.loadBearer();
this.checkRegistrationAvailabilty().subscribe(
(data)=>{this._registrationAvailable = (data.status != 503);},
(error)=>{this._registrationAvailable = (error.status != 503);}
);
);
}
getURL(){
return this.apiURL;
}
registrationAvailable(){
return this._registrationAvailable;
}
loadBearer() {
if (this.cache.has('bearer')) {
if (this.cache.has('bearer')) {
this.setBearer(this.cache.get('bearer'));
this.logger.debug("GeoportalApiService: bearer loaded from cache.");
} else {
this.logger.debug("GeoportalApiService: failed to load bearer from cache.");
}
}
saveBearer() {
this.logger.debug("Saving bearer.");
this.cache.set('bearer', this.bearer);
}
deleteBearer() {
this.cache.remove('bearer');
this.bearer = '';
......@@ -109,9 +109,11 @@ export class GeoportalApiService {
);
}
checkRegistrationAvailabilty():Observable<any>{
return this.http.post<any>(this.apiURL+"/accounts/register/",{},this.httpOptions);
}
sendContactForm(msg:any):Observable<any>
{
let request = this.http.post<any>(this.apiURL+'/contact/',msg,this.httpOptions);
......@@ -312,7 +314,6 @@ export class GeoportalApiService {
}
return bboxString;
}
private isValidOsmType(osmType) {
return (osmType != "" && osmType != null && osmType != undefined); //haesslig lange abfrage, lieber in eigene methode
}
......@@ -350,6 +351,9 @@ export class GeoportalApiService {
getTagWhitelist(){
return this.http.get(this.apiURL+"/GeoElements/AvailableOsmTags/",this.httpOptions);
}
/***
......
import { TestBed } from '@angular/core/testing';
import { OsmApiService } from './osm-api.service';
describe('OsmApiService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: OsmApiService = TestBed.get(OsmApiService);
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { GeoportalApiService } from './geoportal-api.service';
import { LogService } from './log.service';
import { HttpClient, HttpHeaders, HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { xml2js } from 'xml2js';
@Injectable({
providedIn: 'root'
})
export class OsmApiService {
private apiURL : string = "";
constructor(
private apiService: GeoportalApiService,
private httpClient: HttpClient,
private logger: LogService
) {
httpClient.get(apiService.getURL()+"/parameters/osm_api_url/").subscribe(
(data)=>{
if(data){
if(data['osm_api_url']){
let url = data['osm_api_url'];
if(url.endsWith(url)){
this.apiURL=url.substr(0,url.length-1);
}else{
this.apiURL=url;
}
}
}
this.logger.debug("OSM-Api-URL set to"+this.apiURL);
},
(error)=>{
console.warn("Error fetching osm_api_url");
}
);
}
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { LogService } from '../services/log.service';
import { CacheService } from '../services/cache.service';
import { LogService } from './log.service';
import { CacheService } from './cache.service';
import { GeoportalApiService } from './geoportal-api.service';
import { OsmApiService } from './osm-api.service';
import { OsmNode } from '../models/OsmNode';
import { KeyValuePair } from '../models/KeyValuePair';
import { map, tap, catchError } from 'rxjs/operators';
......@@ -10,15 +12,52 @@ import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
/*
* Alan:
* Switch case durch alternative, besser wiederverwendbare loesung ersetzt
* Große Funktionen in kleinere aufgeteilt
*/
export class OverpassService {
private apiURL = "http://overpass-api.de/api/interpreter";
//private apiURL="http://geoportal-api.transformationsstadt.de:8888/api/interpreter";
constructor(private httpClient: HttpClient, private cache: CacheService, private logger: LogService) { }
constructor(
private httpClient: HttpClient,
private cache: CacheService,
private logger: LogService,
private apiService: GeoportalApiService,
private osmApiService: OsmApiService
) {
this.getOverpassURL();
apiService.getTagWhitelist().subscribe(
(data)=>{
if(Array.isArray(data)){
this._tagWhiteList = data;
}
console.log("TagWhiteList now: "+JSON.stringify(this._tagWhiteList));
},
(error)=>{
console.warn("Error getting tag whitelist");
}
)
}
getOverpassURL(){
this.httpClient.get(this.apiService.getURL()+"/parameters/overpass_api_url/").subscribe(
(result)=>{
if(result){
if(result['overpass_api_url']){
this.logger.debug("Overpass-API set to "+this.apiURL);
this.apiURL = result['overpass_api_url'];
}
}
},
(error)=>{
console.log("error getting/setting overpas_api");
}
);
}
debug(msg: string) {
this.logger.debug("OverpassService: " + msg);
}
......@@ -33,7 +72,11 @@ export class OverpassService {
return this.httpClient.get(this.apiURL + '?data=[out:json];(' + query + ');out;');
}
getOsmTags(node: OsmNode) {
retryLimit: number=3;
getOsmTags(node: OsmNode,retry?:number) {
if(retry == undefined){
retry = 0;
}
if (node == null || node == undefined) {
this.debug("Node null or undefined. aborting");
return;
......@@ -58,12 +101,20 @@ export class OverpassService {
this.parseResponse(data, node, TagWhiteList);
},
(error) => {
if(error.status == 429 && retry < this.retryLimit){
console.warn("error","overpass throttled. request queued.");
setTimeout(()=>{
this.getOsmTags(node,retry++);},
1500*(retry*retry));
return;
}
this.debug("Error fetching data from overpass.");
this.debug(JSON.stringify(error, null, 3));
this.logger.notify('error', 'error fetching data from overpass.');
}
);
}
getNodeById(id: number) {
if (id == undefined || id == null) {
return;
......@@ -105,21 +156,28 @@ export class OverpassService {
}
}
}
private _tagWhiteList : Array<String>;
private initTagWhiteList() {
let TagWhiteList = new Array<string>();
TagWhiteList.push('name');
TagWhiteList.push('source');
TagWhiteList.push('addr:country');
TagWhiteList.push('addr:street');
TagWhiteList.push('addr:housenumber');
TagWhiteList.push('addr:postcode');
TagWhiteList.push('addr:city');
TagWhiteList.push('email');
TagWhiteList.push('opening_hours');
TagWhiteList.push('start_date');
TagWhiteList.push('operator:type');
if(this._tagWhiteList != undefined){
return this._tagWhiteList;
}
let TagWhiteList = [
'name',
'source',
'addr:country',
'addr:street',
'addr:housenumber',
'addr:postcode',
'addr:city',
'email',
'opening_hours',
'start_date',
'operator:type'
];
return TagWhiteList;
}
private initSupportedTypeMap(node: OsmNode) {
......
......@@ -54,6 +54,15 @@ export class EditComponent implements OnInit {
this.form = this.formBuilder.group({
osmForm:this.formBuilder.group({
name:[this.node.getName()],
addr_street:[this.node.getOsmTagValue('addr:street')],
addr_city:[this.node.getOsmTagValue('addr:city')],
addr_country:[this.node.getOsmTagValue('addr:country')],
addr_housenumber:[this.node.getOsmTagValue('addr:housenumber')],
addr_postcode:[this.node.getOsmTagValue('addr:postcode')],
email:[this.node.getOsmTagValue('email')],
opening_hours:[this.node.getOsmTagValue('opening_hours')],
src:[this.node.getOsmTagValue('source')],
start_date:[this.node.getOsmTagValue('start_date')]
}),
goodplaceForm:this.formBuilder.group({
description:[this.node.getDescription()],
......@@ -89,6 +98,13 @@ export class EditComponent implements OnInit {
}
this.node.removeTag(key);
}
private updateOsmTag(value, key: string): void {
if (value!= undefined && value != null && (typeof(value)=="string" && value.length > 0)) {
this.node.setOsmTag(key, value);
return;
}
this.node.removeOsmTag(key);
}
private updateNode(){
let osmForm = this.form.get('osmForm').value;
......@@ -97,7 +113,16 @@ export class EditComponent implements OnInit {
} else {
this.node.setName(this.node.getOsmTagValue('name'));
}
this.node.setOsmTag('addr:street',osmForm.addr_street);
this.node.setOsmTag('addr:country',osmForm.addr_country);
this.node.setOsmTag('addr:city',osmForm.addr_city);
this.node.setOsmTag('addr:housenumber',osmForm.addr_housenumber);
this.node.setOsmTag('addr:postcode',osmForm.addr_postcode);
this.node.setOsmTag('source',osmForm.src);
this.node.setOsmTag('opening_hours',osmForm.opening_hours);
this.node.setOsmTag('start_date',osmForm.start_date);
this.node.setOsmTag('email',osmForm.email);
console.log("Setting osm-tags to: "+JSON.stringify(this.node.osmtags));
let goodplaceForm = this.form.get('goodplaceForm').value;
if (goodplaceForm.description) {
this.node.setDescription(goodplaceForm.description);
......
......@@ -5,8 +5,7 @@
<div (click)="infoCollapsed= !infoCollapsed" [attr.aria-expanded]="!infoCollapsed"
aria-controls="collapseInfo" class="collapseInfo">
<h5><i class="" aria-hidden="true">&nbsp;</i>Allgemeine
Informationen<i
[ngClass]="{'fa':true,'fa-lg':true,'fa-angle-down':!infoCollapsed,'fa-angle-right':infoCollapsed, 'fa-right':true}"
Informationen<i [ngClass]="{'fa':true,'fa-lg':true,'fa-angle-down':!infoCollapsed,'fa-angle-right':infoCollapsed, 'fa-right':true}"
aria-hidden="true">&nbsp;</i></h5>
</div>
</div>
......@@ -30,7 +29,7 @@
</label>
<div class="col">
<input type="text" class="form-control" id="elementOsmid" value="{{node.getOsmId()}}"
disabled>
[disabled]="!hasToken()">
</div>
<div class="col-auto">
<a href="http://www.openstreetmap.org/copyright" target="_blank"><i aria-hidden="true"
......@@ -43,7 +42,7 @@
</label>
<div class="col">
<input type="text" class="form-control" id="name"
value="{{node.getOsmTagValue('name')}}" disabled placeholder="Keine Angabe bisher.">
value="{{node.getOsmTagValue('name')}}" placeholder="Keine Angabe bisher." [disabled]="!hasToken()">
</div>
<div class="col-auto">
<a href="http://www.openstreetmap.org/copyright" target="_blank"><i aria-hidden="true"
......@@ -56,8 +55,9 @@
<strong>Website</strong>
</label>
<div class="col">
<input type="text" class="form-control" id="website"
value="{{node.getOsmTagValue('source')}}" disabled
<input type="text" class="form-control" id="src"
formControlName="src"
value="{{node.getOsmTagValue('source')}}" [disabled]="!hasToken()"
placeholder="Keine Angabe bisher.">
</div>
<div class="col-auto">
......@@ -70,8 +70,9 @@
<strong>Straße</strong>
</label>
<div class="col">
<input type="text" class="form-control" id="addr:street"
value="{{node.getOsmTagValue('addr:street')}}" disabled
<input type="text" class="form-control" id="addr_street"
formControlName="addr_street"
value="{{node.getOsmTagValue('addr:street')}}" [disabled]="!hasToken()"
placeholder="Keine Angabe bisher.">
</div>
<div class="col-auto">
......@@ -84,8 +85,9 @@
<strong>Hausnummer</strong>
</label>
<div class="col">
<input type="text" class="form-control" id="addr:housenumber"
value="{{node.getOsmTagValue('addr:housenumber')}}" disabled
<input type="text" class="form-control" id="addr_housenumber"
formControlName="addr_housenumber"
value="{{node.getOsmTagValue('addr:housenumber')}}" [disabled]="!hasToken()"
placeholder="Keine Angabe bisher.">
</div>
<div class="col-auto">
......@@ -98,8 +100,9 @@
<strong>Postleitzahl</strong>
</label>
<div class="col">
<input type="text" class="form-control" id="addr:postcode"
value="{{node.getOsmTagValue('addr:postcode')}}" disabled
<input type="text" class="form-control" id="addr_postcode"
formControlName="addr_postcode"
value="{{node.getOsmTagValue('addr:postcode')}}" [disabled]="!hasToken()"
placeholder="Keine Angabe bisher.">
</div>
<div class="col-auto">
......@@ -112,8 +115,9 @@
<strong>Stadt</strong>
</label>
<div class="col">
<input type="text" class="form-control" id="addr:city"
value="{{node.getOsmTagValue('addr:city')}}" disabled
<input type="text" class="form-control" id="addr_city"
formControlName="addr_city"
value="{{node.getOsmTagValue('addr:city')}}" [disabled]="!hasToken()"
placeholder="Keine Angabe bisher.">
</div>
<div class="col-auto">
......@@ -126,8 +130,9 @@
<strong>Land</strong>
</label>
<div class="col">
<input type="text" class="form-control" id="addr:country"
value="{{node.getOsmTagValue('addr:country')}}" disabled
<input type="text" class="form-control" id="addr_country"
formControlName="addr_country"
value="{{node.getOsmTagValue('addr:country')}}" [disabled]="!hasToken()"
placeholder="Keine Angabe bisher.">
</div>
<div class="col-auto">
......@@ -141,7 +146,8 @@
</label>
<div class="col">
<input type="text" class="form-control" id="email"
value="{{node.getOsmTagValue('email')}}" disabled
formControlName="email"
value="{{node.getOsmTagValue('email')}}" [disabled]="!hasToken()"
placeholder="Keine Angabe bisher.">
</div>
<div class="col-auto">
......@@ -155,7 +161,8 @@
</label>
<div class="col">
<input type="text" class="form-control" id="opening_hours"
value="{{node.getOsmTagValue('opening_hours')}}" disabled
formControlName="opening_hours"
value="{{node.getOsmTagValue('opening_hours')}}" [disabled]="!hasToken()"
placeholder="Keine Angabe bisher.">
</div>
<div class="col-auto">
......
import { Component, OnInit, Input } from '@angular/core';
import { OsmNode } from '../../../models/OsmNode';
import { AuthService } from '../../../services/auth.service';
import { FormsModule ,FormBuilder, ReactiveFormsModule, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-osminformation',
......@@ -11,7 +12,7 @@ export class OsminformationComponent implements OnInit {
@Input('form') form : FormGroup;
public infoCollapsed:boolean=false ;
constructor() { }
constructor(private authService: AuthService) { }
ngOnInit() {
}
......@@ -23,7 +24,14 @@ export class OsminformationComponent implements OnInit {
}
}
}
hasToken(){
let user = this.authService.getCurrentUser();
if(user == null){
return false;
}
return user.hasOAuthToken();
}
translateTagKey(key:string){
switch(key){
......
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GeoPortal</title>
<title>GeoPortal des Guten Lebens</title>
<base href="/">
<script src="assets/js/ol.js"></script>
<link rel="stylesheet" href="/assets/css/ol.css">
......
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