diff --git a/backend/api.py b/backend/api.py index c3698c30..6149f428 100755 --- a/backend/api.py +++ b/backend/api.py @@ -1,6 +1,6 @@ from flask import Flask, request, Blueprint,Response, jsonify, url_for from routes import main as main_blueprint -from config import DATA_IMAGES_PATH +from config import DATA_IMAGES_PATH, DATA_NOTICES_PATH from pypnusershub import routes as fnauth import fnmatch import re @@ -142,8 +142,6 @@ def returnCurrentUser(id_role = None): return jsonify(error=exception), 400 - - @api.route('/api/site/', methods=['DELETE']) @fnauth.check_auth(6, False, None, None) def deleteSite(id_site): @@ -165,7 +163,7 @@ def deleteSite(id_site): return jsonify('error'), 400 @api.route('/api/addSite', methods=['POST']) -@fnauth.check_auth(6, False, None, None) +@fnauth.check_auth(2, False, None, None) def add_site(): try: data = dict(request.get_json()) @@ -178,7 +176,7 @@ def add_site(): @api.route('/api/updateSite', methods=['PATCH']) -@fnauth.check_auth(6, False, None, None) +@fnauth.check_auth(2, False, None, None) def update_site(): site = request.get_json() models.CorSiteSthemeTheme.query.filter_by(id_site=site.get('id_site')).delete() @@ -188,7 +186,7 @@ def update_site(): @api.route('/api/addThemes', methods=['POST']) -@fnauth.check_auth(6, False, None, None) +@fnauth.check_auth(2, False, None, None) def add_cor_site_theme_stheme(): data = request.get_json().get('data') for d in data: @@ -204,7 +202,7 @@ def add_cor_site_theme_stheme(): @api.route('/api/addPhotos', methods=['POST']) -@fnauth.check_auth(6, False, None, None) +@fnauth.check_auth(2, False, None, None) def upload_file(): base_path = './static/' + DATA_IMAGES_PATH data = request.form.getlist('data') @@ -218,7 +216,6 @@ def upload_file(): #models.TSite.query.filter_by(id_site=d_serialized.get('id_site')).delete() #db.session.commit() return jsonify(error='image_already_exist', image=d_serialized.get('path_file_photo')), 400 - print ('d_serialized', d_serialized) main_photo = d_serialized.get('main_photo') del d_serialized['main_photo'] photo = models.TPhoto(**d_serialized) @@ -233,9 +230,16 @@ def upload_file(): image.save(os.path.join(base_path + image.filename)) return jsonify('photo added successfully'), 200 +@api.route('/api/addNotices', methods=['POST']) +@fnauth.check_auth(2, False, None, None) +def upload_notice(): + base_path = './static/' + DATA_NOTICES_PATH + notice = request.files.get('notice') + notice.save(os.path.join(base_path + notice.filename)) + return jsonify('notice added successfully'), 200 @api.route('/api/updatePhoto', methods=['PATCH']) -@fnauth.check_auth(6, False, None, None) +@fnauth.check_auth(2, False, None, None) def update_photo(): base_path = './static/' + DATA_IMAGES_PATH data = request.form.get('data') @@ -278,23 +282,17 @@ def deletePhotos(): os.remove(base_path + fileName) return jsonify('site has been deleted'), 200 - - - @api.route('/api/communes', methods=['GET']) def returnAllcommunes(): try: get_all_communes = models.Communes.query.order_by('nom_commune').all() - print('get_all_communes', get_all_communes) communes= models.CommunesSchema(many=True).dump(get_all_communes).data - print('communes', communes) return jsonify(communes), 200 except Exception as exception: return ('error'), 400 - @api.route('/api/logout', methods=['GET']) def logout(): - resp = Response(jsonify({'msg':'logout'}), 200) + resp = Response('', 200) resp.delete_cookie('token') return resp \ No newline at end of file diff --git a/backend/models.py b/backend/models.py index fbf2cc9a..db75c0ae 100755 --- a/backend/models.py +++ b/backend/models.py @@ -25,7 +25,7 @@ class TSite(db.Model): testim_site = db.Column(db.String) code_city_site = db.Column(db.String) alti_site = db.Column(db.Integer) - path_file_guide_site = db.Column(db.String(1)) + path_file_guide_site = db.Column(db.String) publish_site = db.Column(db.Boolean) geom = db.Column(Geometry(geometry_type='POINT', srid=4326)) main_photo = db.Column(db.Integer) diff --git a/front-backOffice/src/app/add-photo/add-photo.component.html b/front-backOffice/src/app/add-photo/add-photo.component.html index 078490fe..51703d68 100644 --- a/front-backOffice/src/app/add-photo/add-photo.component.html +++ b/front-backOffice/src/app/add-photo/add-photo.component.html @@ -12,7 +12,7 @@ Supprimer la photo
-
Afficher la photo :
+
Publier la photo :
- +
- +
diff --git a/front-backOffice/src/app/add-site/add-site.component.html b/front-backOffice/src/app/add-site/add-site.component.html index 374a28f4..0c4733f6 100644 --- a/front-backOffice/src/app/add-site/add-site.component.html +++ b/front-backOffice/src/app/add-site/add-site.component.html @@ -88,25 +88,28 @@
* Champs requis
-
{{photo.name}}
-
+
{{photo.name}}
+
-
+
- -
{{noticeName}}
+ +
{{noticeName}}
- @@ -117,8 +120,8 @@
-
+
diff --git a/front-backOffice/src/app/add-site/add-site.component.ts b/front-backOffice/src/app/add-site/add-site.component.ts index 3b3e3aab..8b7926bf 100644 --- a/front-backOffice/src/app/add-site/add-site.component.ts +++ b/front-backOffice/src/app/add-site/add-site.component.ts @@ -1,7 +1,7 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core'; import { SitesService } from '../services/sites.service'; import { HttpEventType } from '@angular/common/http'; -import { Router, ActivatedRoute } from '@angular/router'; +import { Router, ActivatedRoute, NavigationEnd } from '@angular/router'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; import { FormGroup } from '@angular/forms'; import { tileLayer, latLng, Map, Layer } from 'leaflet'; @@ -19,8 +19,8 @@ import { AuthService } from '../services/auth.service'; styleUrls: ['./add-site.component.scss'], }) -export class AddSiteComponent implements OnInit { - selectedFiles: File[]; +export class AddSiteComponent implements OnInit, OnDestroy { + selectedFile: File[]; modalRef: NgbModalRef; selectedSubthemes = []; photos = []; @@ -32,6 +32,7 @@ export class AddSiteComponent implements OnInit { subthemes: any; loadForm = false; map; + mySubscription; id_site = null; markers = []; @@ -85,7 +86,7 @@ export class AddSiteComponent implements OnInit { toast_msg: string; communes: undefined; currentUser: any; - zoom: number; + zoom = 10; constructor( private sitesService: SitesService, public formService: FormService, @@ -120,6 +121,16 @@ export class AddSiteComponent implements OnInit { } onMapReady(map: Map) { + L.control.scale().addTo(map); + const street = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'); + const ignLayer = L.tileLayer(this.layerUrl( + Conf.ign_Key, 'GEOGRAPHICALGRIDSYSTEMS.MAPS' + )); + const baseLayers = { + 'IGN ': ignLayer, + 'OSM': street + }; + L.control.layers(baseLayers).addTo(map); const info = new L.Control(); info.setPosition('topleft'); info.onAdd = () => { @@ -134,7 +145,6 @@ export class AddSiteComponent implements OnInit { return container; }; info.addTo(map); - map.addLayer(this.drawnItems); L.EditToolbar.Delete.include({ removeAllLayers: false @@ -152,7 +162,6 @@ export class AddSiteComponent implements OnInit { map.addControl(this.drawControl); }); - map.on(L.Draw.Event.EDITED, (event) => { let layer = (event as any).layers._layers; layer = layer[Object.keys(layer)[0]]; @@ -183,18 +192,14 @@ export class AddSiteComponent implements OnInit { } onDrawReady(drawControl) { - this.drawControl = drawControl; if (this.id_site) { this.map.removeControl(this.drawControl); } } - onFileSelected(event) { - console.log('event', event); - this.selectedFiles = event.target.files; - } noticeSelect(event) { + this.selectedFile = event.target.files; if (event.target.files && event.target.files.length > 0) { this.noticeName = event.target.files[0].name; this.noticeLaoded = true; @@ -205,6 +210,15 @@ export class AddSiteComponent implements OnInit { this.noticeName = null; this.noticeLaoded = false; this.siteForm.controls['notice'].reset(); + this.selectedFile = null; + } + + uploadNotice() { + const notice: FormData = new FormData(); + if (this.noticeName) { + notice.append('notice', this.selectedFile[0], this.selectedFile[0].name); + this.sitesService.addNotices(notice).subscribe(); + } } onCancel() { @@ -214,9 +228,15 @@ export class AddSiteComponent implements OnInit { submitSite(siteForm) { this.alert = null; + let path_file_guide_site = null; + if (this.noticeName) { + path_file_guide_site = this.selectedFile[0].name; + } if (siteForm.valid && this.photos.length > 0) { this.siteJson = _.omit(siteForm.value, ['id_theme', 'notice', 'lat', 'lng', 'id_stheme']); this.siteJson.geom = 'SRID=4326;POINT(' + siteForm.value.lng + ' ' + siteForm.value.lat + ')'; + this.siteJson.path_file_guide_site = path_file_guide_site; + // this.uploadNotice(); if (!this.id_site) { this.sitesService.addSite(this.siteJson).subscribe( (site) => { @@ -253,22 +273,6 @@ export class AddSiteComponent implements OnInit { this.photos.push(photo); } - /* - uploadImage() { - console.log('this.selectedFile,', this.selectedFiles); - const image: FormData = new FormData(); - _.forEach(this.selectedFiles, (filesItem) => { - image.append('image', filesItem, filesItem.name); - }); - this.sitesService.addPhotos(image).subscribe( - (event) => { - if (event.type === HttpEventType.UploadProgress) { - console.log('resUplod', event.loaded); - } - } - ); - } - */ addPhotos(id_site, id_theme, id_stheme, ) { const photosData: FormData = new FormData(); @@ -325,6 +329,16 @@ export class AddSiteComponent implements OnInit { this.siteForm.disable(); this.edit_btn = false; this.toastr.success(this.toast_msg, '', { positionClass: 'toast-bottom-right' }); + // ###### can reload the same route ####### + this.router.routeReuseStrategy.shouldReuseRoute = function () { + return false; + }; + this.mySubscription = this.router.events.subscribe((event) => { + if (event instanceof NavigationEnd) { + this.router.navigated = false; + } + }); + // ########## this.router.navigate(['/sites/details/', id_site]); }, (err) => { @@ -357,6 +371,7 @@ export class AddSiteComponent implements OnInit { this.initMarker(this.site.geom[0], this.site.geom[1]); this.patchForm(); this.loadForm = true; + this.center = latLng(this.site.geom); this.siteForm.disable(); this.themes_onChange(); this.latlan_onChange(); @@ -442,17 +457,15 @@ export class AddSiteComponent implements OnInit { this.toast_msg = "Point d'observation mis à jour"; this.edit_btn_text = 'Éditer'; if (this.deleted_photos.length > 0) { - this.sitesService.deletePhotos(this.deleted_photos).subscribe( - () => '', - (err) => { - if (err.status === 403) { - this.router.navigate(['']); - this.toastr.error('votre session est expirée', '', { positionClass: 'toast-bottom-right' }); - } - } - ); + this.sitesService.deletePhotos(this.deleted_photos).subscribe(); } this.addPhotos(this.id_site, themes, sthemes); + }, + (err) => { + if (err.status === 403) { + this.router.navigate(['']); + this.toastr.error('votre session est expirée', '', { positionClass: 'toast-bottom-right' }); + } } ); } @@ -529,9 +542,26 @@ export class AddSiteComponent implements OnInit { 'id_stheme': this.site.subthemes, 'code_city_site': this.site.code_city_site, 'legend_site': this.site.legend_site, - 'notice': null, }); + if (this.site.path_file_guide_site) { + this.noticeLaoded = true; + this.noticeName = this.site.path_file_guide_site; + } + + } + layerUrl(key, layer) { + return 'http://wxs.ign.fr/' + key + + '/geoportail/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&' + + 'LAYER=' + layer + '&STYLE=normal&TILEMATRIXSET=PM&' + + 'TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&FORMAT=image%2Fjpeg'; } + ngOnDestroy() { + if (this.mySubscription) { + this.mySubscription.unsubscribe(); + } + } } + + diff --git a/front-backOffice/src/app/app-routing.module.ts b/front-backOffice/src/app/app-routing.module.ts index 8460758a..a16ec2d5 100644 --- a/front-backOffice/src/app/app-routing.module.ts +++ b/front-backOffice/src/app/app-routing.module.ts @@ -12,13 +12,13 @@ const routes: Routes = [ { path: 'sites', component: ManageSitesComponent, canActivate : [AuthGuard] }, { path: 'gallery', component: GalleryComponent, canActivate : [AuthGuard] }, { path: 'sites/form', component: AddSiteComponent, canActivate : [AuthGuard] }, - { path: 'sites/details/:id', component: AddSiteComponent, canActivate : [AuthGuard]}, + { path: 'sites/details/:id', component: AddSiteComponent, canActivate : [AuthGuard], runGuardsAndResolvers: 'always'}, { path: '', component: LoginPageComponent }, { path: '**', redirectTo: 'login' }, ]; @NgModule({ - imports: [RouterModule.forRoot(routes)], + imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload' })], exports: [RouterModule] }) export class AppRoutingModule { diff --git a/front-backOffice/src/app/header/header.component.html b/front-backOffice/src/app/header/header.component.html index 4dd00c40..e5baed8a 100644 --- a/front-backOffice/src/app/header/header.component.html +++ b/front-backOffice/src/app/header/header.component.html @@ -9,10 +9,10 @@