added webapp to view travels

This commit is contained in:
arnaucode
2018-06-16 21:15:56 +02:00
parent 3691142a88
commit 1d9f657bba
19 changed files with 924 additions and 1 deletions

11
app/views/navbar.html Executable file
View File

@@ -0,0 +1,11 @@
<div ng-controller="NavbarCtrl">
<div class="navbar c_grey700">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/">CommonRoutes</a>
<a class="navbar-brand">|</a>
<a class="navbar-brand" href="/app/#!/travels">Travels</a>
</div>
</div>
</div>
</div>

14
app/views/navbar.js Executable file
View File

@@ -0,0 +1,14 @@
'use strict';
angular.module('app.navbar', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/navbar', {
templateUrl: 'views/navbar/navbar.html',
controller: 'NavbarCtrl'
});
}])
.controller('NavbarCtrl', function($scope) {
});

48
app/views/travel/travel.html Executable file
View File

@@ -0,0 +1,48 @@
<div class="container">
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<div class="panel">
<div class="panel-body">
<div class="pull-right">
<!-- <div class="row-picture" style="font-size:140%; text-align:right;" title="user">
<img style="width:40px;" class="circle" ng-src="{{travel.user.avatar}}" alt="icon"> {{travel.user.username}}
</div> -->
{{travel.date | date:"dd/MM HH:mm a"}}
</div>
<div class="list-group">
<div class="list-group-item">
<div class="pull-right"></div>
<h4>
<i ng-show="travel.type=='offering'" class="fa fa-car fa-2x"></i>
<i ng-show="travel.type=='asking'" class="fa fa-question fa-2x"></i>
<i ng-show="travel.type=='package'" class="fa fa-archive fa-2x"></i>
{{travel.title}}
</h4>
</div>
</div>
<p>
From: <b>{{travel.from.name}}</b>
</p>
<p>
To: <b>{{travel.from.name}}</b>
</p>
<p ng-show="travel.description">
Description: <b>{{travel.description}}</b>
</p>
<p ng-show="travel.package">
Can carry package
</p>
</div>
</div>
<div class="panel">
<div class="panel-heading c_deepPurple300">
<h3 class="panel-title">Map</h3>
</div>
<div class="panel-body">
<leaflet width="100%" height="400px" markers="markers" center="center"
tiles="tiles" id="map-simple-map"></leaflet>
</div>
</div>
</div>
</div>

61
app/views/travel/travel.js Executable file
View File

@@ -0,0 +1,61 @@
'use strict';
angular.module('app.travel', ['ngRoute', 'ui-leaflet'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/travel/:travelid', {
templateUrl: 'views/travel/travel.html',
controller: 'TravelCtrl'
});
}])
.controller('TravelCtrl', function($scope, $http, $routeParams,
leafletData, leafletBoundsHelpers) {
$scope.travel = {};
//map
$scope.center = {
/*lat: 0,
lng: 0,
zoom: 1*/
};
$scope.bounds = {};
$scope.markers = [];
$scope.tiles = {
url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
options: {
attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}
};
$http.get(urlapi + 'travels/id/' + $routeParams.travelid)
.then(function(data, status, headers, config) {
console.log('data success');
console.log(data);
$scope.travel = data.data;
//map
$scope.markers = [];
$scope.markers.push({
lat: Number($scope.travel.from.lat),
lng: Number($scope.travel.from.long),
message: $scope.travel.from.name
});
$scope.markers.push({
lat: Number($scope.travel.to.lat),
lng: Number($scope.travel.to.long),
message: $scope.travel.to.name
});
$scope.center = {
lat: (Number($scope.travel.from.lat) + Number($scope.travel.to.lat)) / 2,
lng: (Number($scope.travel.from.long) + Number($scope.travel.to.long)) / 2,
zoom: 4
};
}, function(data, status, headers, config) {
console.log('data error');
});
});

52
app/views/travels/travels.html Executable file
View File

@@ -0,0 +1,52 @@
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="panel">
<div class="panel-heading c_deepPurple300">
<h3 class="panel-title">All travels</h3>
</div>
<div class="panel-body" style="max-height: 500px;overflow-y: scroll;">
<table class="table table-striped table-hover ">
<thead>
<tr>
<th>Type</th>
<th>From</th>
<th>To</th>
<th>Date</th>
<!-- <th>User</th> -->
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="travel in travels">
<td>
<i ng-show="travel.type=='offering'" class="fa fa-car fa-2x"></i>
<i ng-show="travel.type=='asking'" class="fa fa-question fa-2x"></i>
<i ng-show="travel.type=='package'" class="fa fa-archive fa-2x"></i>
</td>
<td>{{travel.from.name}}</td>
<td>{{travel.to.name}}</td>
<td>{{travel.date | date:'yyyy/MM/dd'}}</td>
<!-- <td>
<img style="width:30px;" ng-src="{{travel.user.avatar}}" title="{{travel.user.username}}">
</td> -->
<td><a ng-href="#!/travel/{{travel._id}}">View</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel">
<div class="panel-heading c_deepPurple300">
<h3 class="panel-title">Map</h3>
</div>
<div class="panel-body">
<leaflet width="100%" height="500px" markers="markers" paths="paths" center="center"
tiles="tiles" id="map-simple-map"></leaflet>
</div>
</div>
</div>
</div>
</div>

73
app/views/travels/travels.js Executable file
View File

@@ -0,0 +1,73 @@
'use strict';
angular.module('app.travels', ['ngRoute', 'ui-leaflet'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/travels', {
templateUrl: 'views/travels/travels.html',
controller: 'TravelsCtrl'
});
}])
.controller('TravelsCtrl', function($scope, $http) {
$scope.travels = [];
$scope.loadMorePagination = true;
$scope.page = 0;
//map
$scope.center = {};
$scope.bounds = {};
$scope.markers = [];
$scope.paths = [];
$scope.tiles = {
url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
options: {
attribution: '<a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}
};
$http.get(urlapi + 'travels?page=' + $scope.page)
.then(function(data) {
console.log('data success');
console.log(data);
$scope.travels = data.data;
//draw markers on map
$scope.markers = [];
for (var i = 0; i < $scope.travels.length; i++) {
$scope.markers.push({
lat: Number($scope.travels[i].from.lat),
lng: Number($scope.travels[i].from.long),
message: $scope.travels[i].from.name
});
$scope.markers.push({
lat: Number($scope.travels[i].to.lat),
lng: Number($scope.travels[i].to.long),
message: $scope.travels[i].to.name
});
}
//draw lines between markers on map
$scope.paths = {};
var paths = [];
for (var i = 0; i < $scope.markers.length; i++) {
var x = $scope.markers[i].lat;
var y = $scope.markers[i].lng;
paths.push([x, y]);
}
$scope.paths = {
p1: {
color: '#9575CD',
weight: 8,
latlngs: paths
}
};
//var maplines = L.polyline(lines).addTo(map)
$scope.center = {
lat: (Number($scope.travels[0].from.lat) + Number($scope.travels[0].to.lat)) / 2,
lng: (Number($scope.travels[0].from.long) + Number($scope.travels[0].to.long)) / 2,
zoom: 4
};
}, function(data) {
console.log('data error');
});
});