Changeset 28d7d35 for Farmatiko/ClientApp/src/app/home
- Timestamp:
- 01/31/21 06:27:26 (4 years ago)
- Branches:
- master
- Children:
- de9d697
- Parents:
- 7520f88
- Location:
- Farmatiko/ClientApp/src/app/home
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/ClientApp/src/app/home/home.component.css
r7520f88 r28d7d35 2 2 display: flex; 3 3 flex-direction: column; 4 max-height: 500px;5 4 min-width: 300px; 6 5 } … … 27 26 padding: 1em 0; 28 27 } 28 .tableRow:hover { 29 background-color: #D4F2CD; 30 transform: scale(1.0005); 31 } 32 33 h2 button { 34 float: right; 35 padding: 0 5em; 36 } 37 38 #map { 39 height: 100%; 40 } 41 42 .map-frame { 43 border: 2px solid black; 44 height: 100%; 45 } 46 47 .map-wrapper { 48 margin: 0 3em 3em 3em; 49 min-height: 400px; 50 } -
Farmatiko/ClientApp/src/app/home/home.component.html
r7520f88 r28d7d35 14 14 <tr> 15 15 <th>Име</th> 16 <th>Јачина</th>17 16 <th>Форма</th> 18 <th>Начин на издавање</th>19 <th>Производител</th>20 17 <th>Цена</th> 21 <th>Пакување</th>22 18 </tr> 23 19 </thead> 24 20 <tbody> 25 <tr *ngFor="let medicine of filteredMedicines"> 26 <td><a (click)="openMedicineDialog(medicine)">{{ medicine.name }}</a></td> 27 <td>{{ medicine.strength }}</td> 21 <tr *ngFor="let medicine of filteredMedicines" (click)="openMedicineDialog(medicine)" class="tableRow"> 22 <td>{{ medicine.name }}</td> 28 23 <td>{{ medicine.form }}</td> 29 <td>{{ medicine.wayOfIssuing }}</td>30 <td>{{ medicine.manufacturer }}</td>31 24 <td>{{ medicine.price }}</td> 32 <td>{{ medicine.packaging }}</td>33 25 </tr> 34 26 </tbody> … … 39 31 <div class="wrapper"> 40 32 <div class="header"> 41 <h2>Аптеки</h2> 33 <h2>Аптеки 34 <button mat-icon-button color="primary" (click)="refreshMap()" [disabled]="!showMap"> 35 <mat-icon>refresh</mat-icon>Освежи 36 </button> 37 <button mat-icon-button color="accent" [disabled]="clicked" (click)="toggleMap(); clicked = true"> 38 <mat-icon>map</mat-icon>Активирај 39 </button> 40 </h2> 41 <div class="map-wrapper" *ngIf="showMap"> 42 <div class="map-frame"> 43 <div id="map" style="height: 400px;" leaflet [leafletOptions]="options"></div> 44 </div> 45 </div> 46 42 47 <mat-form-field> 43 48 <input matInput (keyup)="applyFilterPharmacies($event.target.value)" placeholder="Пронајди аптека"> … … 49 54 <th>Име</th> 50 55 <th>Локација</th> 51 <th>Адреса</th>52 56 <th>Работи 27/7?</th> 53 57 </tr> 54 58 </thead> 55 59 <tbody> 56 <tr *ngFor="let pharmacy of filteredPharmacies" >57 <td> <a (click)="openPharmacyDialog(pharmacy)">{{ pharmacy.name }}</a></td>60 <tr *ngFor="let pharmacy of filteredPharmacies" (click)="openPharmacyDialog(pharmacy)" class="tableRow"> 61 <td>{{ pharmacy.name }}</td> 58 62 <td>{{ pharmacy.location }}</td> 59 <td >{{ pharmacy.address }}</td>60 <td >{{ pharmacy.workAllTime }}</td>63 <td *ngIf="pharmacy.workAllTime == true">Да</td> 64 <td *ngIf="pharmacy.workAllTime != true">Не</td> 61 65 </tr> 62 66 </tbody> 63 67 </table> 68 64 69 </div> 65 70 </mat-tab> -
Farmatiko/ClientApp/src/app/home/home.component.ts
r7520f88 r28d7d35 5 5 import { MedicineDialogComponent } from '../dialogs/medicine-dialog/medicine-dialog.component'; 6 6 import { PharmacyDialogComponent } from '../dialogs/pharmacy-dialog/pharmacy-dialog.component'; 7 import { latLng, LatLng, tileLayer, marker, icon } from 'leaflet'; 8 import { HttpClient } from '@angular/common/http'; 7 9 8 10 @Component({ … … 16 18 public filteredMedicines: IMedicine[] = []; 17 19 public filteredPharmacies: IPharmacy[] = []; 20 public lat; 21 public lng; 22 clicked = false; 23 showMap: boolean = false; 24 options = { 25 layers: [ 26 tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' }) 27 ], 28 zoom: 8, 29 center: latLng(41.61807, 21.74348) 30 } 18 31 19 constructor(private dataService: DataService, private dialog: MatDialog ) {32 constructor(private dataService: DataService, private dialog: MatDialog, private http: HttpClient) { 20 33 21 34 } … … 34 47 }, 35 48 (err: any) => console.log(err), 36 () => console.log('Pharmacy data retrieved')); 49 () => { 50 this.appendPharmacyMarkers(this.pharmacies); 51 console.log('Pharmacy data retrieved'); 52 }); 53 if (navigator.geolocation) { 54 navigator.geolocation.getCurrentPosition((position) => { 55 if (position) { 56 this.lat = position.coords.latitude; 57 this.lng = position.coords.longitude; 58 let layer = marker([ this.lat, this.lng ], { 59 icon: icon({ 60 iconSize: [ 25, 41 ], 61 iconAnchor: [ 13, 41 ], 62 iconUrl: 'assets/home-icon.png' 63 }) 64 }).bindPopup("Вашата локација"); 65 this.options.layers.push(layer); 66 } 67 }); 68 } 37 69 } 70 71 appendPharmacyMarkers(pharmas: IPharmacy[]) { 72 this.options.layers = []; 73 this.options.layers.push(tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'})); 74 if(this.lat && this.lng) { 75 this.options.layers.push(marker([ this.lat, this.lng ], { 76 icon: icon({ 77 iconSize: [ 25, 41 ], 78 iconAnchor: [ 13, 41 ], 79 iconUrl: 'assets/home-icon.png' 80 }) 81 }).bindPopup("Вашата локација")); 82 } 83 pharmas.forEach((pharmacy) => { 84 this.http.get<any>('https://nominatim.openstreetmap.org/search/?country=Macedonia&city='+pharmacy.location+'&street='+pharmacy.address+'&format=json').subscribe(obj => { 85 console.log(obj); 86 if(obj.length) { 87 let layer = marker([ obj[0]?.lat, obj[0]?.lon ], { 88 icon: icon({ 89 iconSize: [ 25, 41 ], 90 iconAnchor: [ 13, 41 ], 91 iconUrl: 'assets/pharmacy-icon.png' 92 }) 93 }).bindPopup("Аптека: "+pharmacy.name); 94 this.options.layers.push(layer); 95 } 96 }, error => console.error(error)); 97 }); 98 } 99 38 100 39 101 applyFilterMedicines(filterValue: string) { … … 60 122 }, 61 123 (err: any) => console.log(err), 62 () => console.log('Pharmacy data retrieved')); 124 () => { 125 this.appendPharmacyMarkers(this.filteredPharmacies); 126 if(this.showMap) { 127 this.showMap = false; 128 setTimeout(() => this.showMap = true, 300); 129 } 130 console.log('Pharmacy data retrieved') 131 }); 63 132 } 64 133 else { 65 134 this.filteredPharmacies = this.pharmacies; 135 this.appendPharmacyMarkers(this.pharmacies); 136 if(this.showMap) { 137 this.showMap = false; 138 setTimeout(() => this.showMap = true, 300); 139 } 66 140 } 67 141 } … … 80 154 }); 81 155 } 156 157 toggleMap() { 158 this.showMap = !this.showMap; 159 } 160 161 refreshMap() { 162 this.showMap = false; 163 setTimeout(() => this.showMap = true, 300); 164 } 165 82 166 }
Note:
See TracChangeset
for help on using the changeset viewer.