Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amine #24

Merged
merged 3 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions backend/api.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -142,8 +142,6 @@ def returnCurrentUser(id_role = None):
return jsonify(error=exception), 400




@api.route('/api/site/<int:id_site>', methods=['DELETE'])
@fnauth.check_auth(6, False, None, None)
def deleteSite(id_site):
Expand All @@ -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())
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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')
Expand All @@ -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)
Expand All @@ -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')
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions front-backOffice/src/app/add-photo/add-photo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h5 class="modal-title">{{title}} </h5>
<i class="icon-trash delete-photo"></i>Supprimer
la photo</button>
<div class="inner-checkbox form-group">
<div class="label">Afficher la photo :</div>
<div class="label">Publier la photo :</div>
<label class="switch ">
<input formControlName="display_gal_photo" type="checkbox" class="success">
<span class="slider round"></span>
Expand All @@ -38,12 +38,12 @@ <h5 class="modal-title">{{title}} </h5>
</div>
<div class="row form-item">
<div class="col ">
<label class="label" for="datePhoto">Date de prise de la photo*</label>
<label class="label" for="datePhoto">Date approximative </label>
<input InputFeedBack type="text" formControlName="date_photo" id="datePhoto" class="form-control" placeholder="Date Photo">
<app-form-error controlName="date_photo" errorKey="required"></app-form-error>
</div>
<div class="col ">
<label class="label" for="sousTheme">Date filtre*</label>
<label class="label" for="sousTheme">Date de prise de la photo*</label>
<div class="input-group">
<input InputFeedBack formControlName="filter_date" type="date" class="form-control" placeholder="yyyy-mm-dd"
ngbDatepicker #dto="ngbDatepicker">
Expand Down
19 changes: 11 additions & 8 deletions front-backOffice/src/app/add-site/add-site.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,28 @@
<div *ngIf="photoRequired" class="photo-required">* Champs requis</div>
<div class="inner-photo" *ngFor="let photo of photos"><img *ngIf="photo.imgUrl" class="preview-img" width="120"
height="120" [src]="photo.imgUrl">
<div class="photo-ref">{{photo.name}}</div>
<div *ngIf="(edit_btn || !id_site) && currentUser.id_droit_max > 5" class="icon-cancel-circle delete-photo" (click)="deletePhoto(photo)"></div>
<div class="photo-ref">{{photo.name}}</div>
<div *ngIf="(edit_btn || !id_site) && currentUser.id_droit_max > 5" class="icon-cancel-circle delete-photo"
(click)="deletePhoto(photo)"></div>
</div>
<app-add-photo *ngIf="edit_btn || !id_site" (photoModal)='getPhoto($event)' style="display :block"></app-add-photo>
</div>
</div>
<div *ngIf="edit_btn || !id_site">
<div >
<input class="form-group" formControlName="notice" style="display: none" type="file" (change)=noticeSelect($event)
accept="application/pdf" #noticeInput>
<button class="blue-btn" type="button" (click)="noticeInput.click()"><i class="icon-download"></i> Importer
<button *ngIf="!noticeName && edit_btn" class="blue-btn" type="button" (click)="noticeInput.click()"><i class="icon-download"></i> Importer
la notice
technique</button>
<div *ngIf="noticeLaoded" style="padding: 10px">{{noticeName}}<i class="icon-trash remove-file" (click)="removeNotice()"></i></div>
<label *ngIf="noticeName" class="label">notice :</label>
<div *ngIf="noticeName" style="color: #00188F;">{{noticeName}}<i *ngIf="(edit_btn)" class="icon-trash remove-file" (click)="removeNotice()"></i></div>
</div>
<div class="submit-btn-group">
<button type="button" *ngIf="id_site" class="btn btn-outline-warning btn-edit" [class.active_edit]="edit_btn"
(click)="editForm()"> <i class="icon-pen"></i>{{edit_btn_text}}</button>
<button class="btn btn-outline-success btn-submit" type="submit" [disabled]="!edit_btn">{{submit_btn_text}}</button>
<button type="button" *ngIf="id_site && currentUser.id_droit_max > 5" class="btn btn-outline-danger btn-delete" (click)="openDeleteModal(content)">
<button type="button" *ngIf="id_site && currentUser.id_droit_max > 5" class="btn btn-outline-danger btn-delete"
(click)="openDeleteModal(content)">
<i class="icon-trash delete-site"></i>Supprimer
le site</button>
<button class="btn btn-outline-secondary btn-cancel" type="button" (click)=onCancel()>Retour à la liste</button>
Expand All @@ -117,8 +120,8 @@
</div>
</div>
<div class="col-6 col-map">
<div class="map " leaflet leafletDraw [leafletOptions]="options" [(leafletCenter)]="center" [(leafletZoom)]="zoom" [leafletDrawOptions]="drawOptions"
(leafletDrawReady)="onDrawReady($event)" (leafletMapReady)="onMapReady($event)">
<div class="map" leaflet leafletDraw [leafletOptions]="options" [(leafletCenter)]="center" [(leafletZoom)]="zoom"
[leafletDrawOptions]="drawOptions" (leafletDrawReady)="onDrawReady($event)" (leafletMapReady)="onMapReady($event)">
</div>
</div>
</div>
Expand Down
Loading