Browse Source

implemented admin login, added map to travel, added user received likes, added controller to navbar

master
arnaucode 7 years ago
parent
commit
6dd11e1a4c
24 changed files with 338 additions and 81 deletions
  1. +55
    -2
      app.js
  2. +18
    -16
      bower.json
  3. BIN
      img/avatars/chameleon.png
  4. BIN
      img/avatars/clown-fish.png
  5. BIN
      img/avatars/duck.png
  6. BIN
      img/avatars/owl.png
  7. BIN
      img/avatars/penguin.png
  8. BIN
      img/avatars/racoon.png
  9. BIN
      img/avatars/siberian-husky.png
  10. BIN
      img/avatars/sloth.png
  11. BIN
      img/avatars/tiger.png
  12. BIN
      img/avatars/toucan.png
  13. BIN
      img/faircoinpublickey_sample.png
  14. BIN
      img/userProfileBackground.png
  15. +11
    -4
      index.html
  16. +29
    -0
      views/login/login.html
  17. +42
    -0
      views/login/login.js
  18. +7
    -4
      views/main/main.html
  19. +5
    -1
      views/navbar.html
  20. +19
    -0
      views/navbar.js
  21. +32
    -8
      views/travel/travel.html
  22. +58
    -21
      views/travel/travel.js
  23. +34
    -8
      views/user/user.html
  24. +28
    -17
      views/user/user.js

+ 55
- 2
app.js

@ -9,6 +9,8 @@ angular.module('adminApp', [
'ngRoute',
'ngMessages',
'angularBootstrapMaterial',
'app.navbar',
'app.login',
'app.main',
'app.user',
'app.travel'
@ -16,5 +18,56 @@ angular.module('adminApp', [
config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
$routeProvider.otherwise({redirectTo: '/main'});
}]);
//$routeProvider.otherwise({redirectTo: '/main'});
if((localStorage.getItem('cic_admin_token')))
{
console.log(window.location.hash);
if(window.location.hash==='#!/login')
{
window.location='#!/main';
}
$routeProvider.otherwise({redirectTo: '/main'});
}else{
if(window.location!=='#!/login')
{
console.log('app, user no logged');
localStorage.removeItem('cic_admin_token');
localStorage.removeItem('cic_admin_userdata');
window.location='#!/login';
$routeProvider.otherwise({redirectTo: '/login'});
}
}
}])
.factory('httpInterceptor', function httpInterceptor () {
return {
request: function(config) {
return config;
},
requestError: function(config) {
return config;
},
response: function(res) {
return res;
},
responseError: function(res) {
return res;
}
};
})
.factory('api', function ($http) {
return {
init: function () {
$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('cic_admin_token');
$http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('cic_admin_token');
}
};
})
.run(function (api) {
api.init();
});

+ 18
- 16
bower.json

@ -1,18 +1,20 @@
{
"name": "carsincommonAdminWeb",
"description": "carsincommonAdminWeb",
"version": "0.0.0",
"homepage": "https://github.com/arnaucode/carsincommonAdmin",
"license": "MIT",
"private": true,
"dependencies": {
"angular": "^1.6.2",
"angular-route": "^1.6.1",
"angular-chart.js": "^1.1.1",
"vis": "^4.18.1",
"mui": "^0.9.20",
"angular-bootstrap-material": "abm#^0.1.4",
"angular-bootstrap": "^2.5.0",
"angular-messages": "^1.6.5"
}
"name": "carsincommonAdminWeb",
"description": "carsincommonAdminWeb",
"version": "0.0.0",
"homepage": "https://github.com/arnaucode/carsincommonAdmin",
"license": "MIT",
"private": true,
"dependencies": {
"angular": "^1.6.2",
"angular-route": "^1.6.1",
"angular-chart.js": "^1.1.1",
"vis": "^4.18.1",
"mui": "^0.9.20",
"angular-bootstrap-material": "abm#^0.1.4",
"angular-bootstrap": "^2.5.0",
"angular-messages": "^1.6.5",
"components-font-awesome": "^4.7.0",
"ui-leaflet": "^2.0.0"
}
}

BIN
img/avatars/chameleon.png

Before After
Width: 512  |  Height: 512  |  Size: 15 KiB

BIN
img/avatars/clown-fish.png

Before After
Width: 512  |  Height: 512  |  Size: 21 KiB

BIN
img/avatars/duck.png

Before After
Width: 512  |  Height: 512  |  Size: 9.6 KiB

BIN
img/avatars/owl.png

Before After
Width: 512  |  Height: 512  |  Size: 15 KiB

BIN
img/avatars/penguin.png

Before After
Width: 512  |  Height: 512  |  Size: 14 KiB

BIN
img/avatars/racoon.png

Before After
Width: 512  |  Height: 512  |  Size: 13 KiB

BIN
img/avatars/siberian-husky.png

Before After
Width: 512  |  Height: 512  |  Size: 19 KiB

BIN
img/avatars/sloth.png

Before After
Width: 512  |  Height: 512  |  Size: 15 KiB

BIN
img/avatars/tiger.png

Before After
Width: 512  |  Height: 512  |  Size: 22 KiB

BIN
img/avatars/toucan.png

Before After
Width: 512  |  Height: 512  |  Size: 11 KiB

BIN
img/faircoinpublickey_sample.png

Before After
Width: 375  |  Height: 377  |  Size: 21 KiB

BIN
img/userProfileBackground.png

Before After
Width: 634  |  Height: 393  |  Size: 245 KiB

+ 11
- 4
index.html

@ -11,6 +11,9 @@
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,400,500,700">
<link rel="stylesheet" href="//fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="bower_components/components-font-awesome/css/font-awesome.min.css">
<link href="css/style.css" rel="stylesheet">
<link href="css/colors.css" rel="stylesheet">
@ -21,6 +24,8 @@
</head>
<body ng-app="adminApp">
<div ng-include="'views/navbar.html'"></div>
<div ng-view></div>
@ -45,10 +50,10 @@
<!-- openstreetmaps angular - leaflet -->
<!--<script src="bower_components/leaflet/dist/leaflet.js"></script>
<script src="bower_components/angular-simple-logger/dist/angular-simple-logger.js"></script>
<script src="bower_components/ui-leaflet/dist/ui-leaflet.js"></script>
<link rel="stylesheet" href="bower_components/leaflet/dist/leaflet.css" />-->
<script src="bower_components/leaflet/dist/leaflet.js"></script>
<script src="bower_components/angular-simple-logger/dist/angular-simple-logger.js"></script>
<script src="bower_components/ui-leaflet/dist/ui-leaflet.js"></script>
<link rel="stylesheet" href="bower_components/leaflet/dist/leaflet.css" />
<script type="text/javascript" src="bower_components/vis/dist/vis.min.js"></script>
<link href="bower_components/vis/dist/vis.min.css" rel="stylesheet" type="text/css" />
@ -57,6 +62,8 @@
<!-- your app's js -->
<script src="app.js"></script>
<script src="views/navbar.js"></script>
<script src="views/login/login.js"></script>
<script src="views/main/main.js"></script>
<script src="views/user/user.js"></script>
<script src="views/travel/travel.js"></script>

+ 29
- 0
views/login/login.html

@ -0,0 +1,29 @@
<div class="container">
<div class="row">
<div class="col-sm-4">
</div>
<div class="col-sm-4">
<div class="panel">
<div class="panel-heading c_deepPurple300">
<h3 class="panel-title">Login</h3>
</div>
<div class="panel-body">
<div class="form-group label-floating">
<input ng-model="user.username" abmFormControl class="form-control" id="inputUsername" placeholder="Username" type="text">
</div>
<div class="form-group">
<input ng-model="user.password" abmFormControl class="form-control" id="inputPassword" placeholder="Password" type="password">
</div>
<div ng-click="doLogin()" class="btn btn-raised c_deepPurple300 pull-right">Login</div>
</div>
</div>
</div>
<div class="col-sm-4">
</div>
</div>
</div>

+ 42
- 0
views/login/login.js

@ -0,0 +1,42 @@
'use strict';
angular.module('app.login', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/login', {
templateUrl: 'views/login/login.html',
controller: 'LoginCtrl'
});
}])
.controller('LoginCtrl', function($scope, $http, $routeParams) {
$scope.user = {};
$scope.doLogin = function() {
console.log('Doing login', $scope.user);
$http({
url: urlapi + 'admin/login',
method: "POST",
data: $scope.user
})
.then(function(response) {
console.log("response: ");
console.log(response.data);
if (response.data.success == true)
{
localStorage.setItem("cic_admin_token", response.data.token);
localStorage.setItem("cic_admin_userdata", JSON.stringify(response.data.user));
window.location.reload();
}else{
console.log("login failed");
}
},
function(response) { // optional
// failed
console.log(response);
});
};
});

+ 7
- 4
views/main/main.html

@ -1,6 +1,3 @@
<div ng-include="'views/navbar.html'"></div>
<div class="container">
<div class="row">
<div class="col-sm-4">
@ -18,6 +15,8 @@
<h4 class="list-group-item-heading">{{user.username}}</h4>
<p class="list-group-item-text">{{user.description}}</p>
<p class="list-group-item-text">{{user.travels.length}} published travels</p>
<p class="list-group-item-text">{{user.likes.length}} likes</p>
</div>
<div class="list-group-separator"></div>
</a>
@ -46,7 +45,11 @@
</thead>
<tbody>
<tr ng-repeat="travel in travels">
<td>{{travel.type}}</td>
<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.title}}</td>
<td>{{travel.date | date}}</td>
<td>

+ 5
- 1
views/navbar.html

@ -1,4 +1,4 @@
<div ng-controller="NavbarCtrl">
<div class="navbar c_grey700">
<div class="container-fluid">
<div class="navbar-header">
@ -36,3 +36,7 @@
</div>
</div>
</div>
<!--
<div ng-click="goBack()" class="btn"><span class="glyphicon glyphicon-arrow-left"></span> Back</div>
-->
</div>

+ 19
- 0
views/navbar.js

@ -0,0 +1,19 @@
'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, $http, $routeParams, $location) {
$scope.locationHash = $location.path();
console.log($scope.locationHash);
$scope.goBack = function() {
console.log("goBack");
window.history.back();
};
});

+ 32
- 8
views/travel/travel.html

@ -1,6 +1,3 @@
<div ng-include="'views/navbar.html'"></div>
<div class="container">
<div class="row">
<div class="col-sm-4">
@ -9,11 +6,25 @@
<h3 class="panel-title">{{travel.title}}</h3>
</div>
<div class="panel-body">
<div class="list-group">
<a ng-href="#!/user/{{user._id}}" class="list-group-item">
<div class="row-picture">
<img class="circle" ng-src="{{travel.user.avatar}}" alt="icon">
</div>
<div class="row-content">
<h4 class="list-group-item-heading">{{travel.user.username}}</h4>
<p class="list-group-item-text">@{{travel.user.telegram}}</p>
<p class="list-group-item-text">{{travel.user.phone}}</p>
</div>
<div class="list-group-separator"></div>
</a>
</div>
<p>
From: {{travel.from.name}}
From: <b>{{travel.from.name}}</b>
</p>
<p>
To: {{travel.from.name}}
To: <b>{{travel.from.name}}</b>
</p>
<p ng-show="travel.package">
Can transport package
@ -25,11 +36,12 @@
<h3 class="panel-title">Map</h3>
</div>
<div class="panel-body">
here the map
<leaflet width="100%" height="300px" markers="markers" center="center"
tiles="tiles" id="map-simple-map"></leaflet>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-3">
<div class="panel">
<div class="panel-heading c_deepPurple300">
<h3 class="panel-title">{{travel.joinPetitions.length}} Pendent joins</h3>
@ -52,7 +64,7 @@
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-3">
<div class="panel">
<div class="panel-heading c_deepPurple300">
<h3 class="panel-title">Accepted users {{travel.joins.length}}/{{travel.seats}}</h3>
@ -74,4 +86,16 @@
</div>
</div>
</div>
<div class="col-sm-2">
<div class="panel">
<div class="panel-heading c_deepPurple500">
<h3 class="panel-title">Admin actions</h3>
</div>
<div class="panel-body">
<div class="btn btn-block btn-sm c_orange300">Ban travel</div>
<div class="btn btn-block btn-sm c_red300">Delete travel</div>
</div>
</div>
</div>
</div>

+ 58
- 21
views/travel/travel.js

@ -1,23 +1,60 @@
'use strict';
angular.module('app.travel', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/travel/:travelid', {
templateUrl: 'views/travel/travel.html',
controller: 'TravelCtrl'
});
}])
.controller('TravelCtrl', function($scope, $http, $routeParams) {
$scope.travel = {};
$http.get(urlapi + 'travels/id/' + $routeParams.travelid)
.then(function(data, status, headers, config) {
console.log('data success');
console.log(data);
$scope.travel = data.data;
}, function(data, status, headers, config) {
console.log('data error');
});
});
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');
});
});

+ 34
- 8
views/user/user.html

@ -1,6 +1,3 @@
<div ng-include="'views/navbar.html'"></div>
<div class="container">
<div class="row">
<div class="col-sm-4">
@ -10,7 +7,7 @@
</div>
<div class="panel-body">
<div class="list-group">
<a ng-href="#!/user" class="list-group-item">
<a class="list-group-item">
<div class="row-picture">
<img class="circle" ng-src="{{user.avatar}}" alt="icon">
</div>
@ -34,14 +31,26 @@
</div>
<div class="panel">
<div class="panel-heading c_deepPurple300">
<h3 class="panel-title">User likes</h3>
<h3 class="panel-title">User received likes ({{user.likes.length}})</h3>
</div>
<div class="panel-body">
Panel content
<div class="list-group">
<a ng-repeat="user in likes" ng-href="#!/user/{{user._id}}" class="list-group-item">
<div class="row-picture">
<img class="circle" ng-src="{{user.avatar}}" alt="icon">
</div>
<div class="row-content">
<h4 class="list-group-item-heading">{{user.username}}</h4>
<p class="list-group-item-text">{{user.description}}</p>
</div>
<div class="list-group-separator"></div>
</a>
</div>
</div>
</div>
</div>
<div class="col-sm-8">
<div class="col-sm-6">
<div class="panel">
<div class="panel-heading c_deepPurple300">
<h3 class="panel-title">User travels</h3>
@ -60,7 +69,11 @@
</thead>
<tbody>
<tr ng-repeat="travel in user.travels">
<td>{{travel.type}}</td>
<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.title}}</td>
<td>{{travel.date | date}}</td>
<td>
@ -76,5 +89,18 @@
</div>
</div>
</div>
<div class="col-sm-2">
<div class="panel">
<div class="panel-heading c_deepPurple500">
<h3 class="panel-title">Admin actions</h3>
</div>
<div class="panel-body">
<div class="btn btn-block btn-sm c_orange300">Ban user</div>
<div class="btn btn-block btn-sm c_red300">Delete user</div>
</div>
</div>
</div>
</div>
</div>

+ 28
- 17
views/user/user.js

@ -2,22 +2,33 @@
angular.module('app.user', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/user/:userid', {
templateUrl: 'views/user/user.html',
controller: 'UserCtrl'
});
}])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/user/:userid', {
templateUrl: 'views/user/user.html',
controller: 'UserCtrl'
});
}])
.controller('UserCtrl', function($scope, $http, $routeParams) {
$scope.user = {};
$http.get(urlapi + 'users/id/' + $routeParams.userid)
.then(function(data, status, headers, config) {
console.log('data success');
console.log(data);
.controller('UserCtrl', function($scope, $http, $routeParams) {
$scope.user = {};
$scope.likes = {};
$http.get(urlapi + 'users/id/' + $routeParams.userid)
.then(function(data, status, headers, config) {
console.log('data success');
console.log(data);
$scope.user = data.data;
}, function(data, status, headers, config) {
console.log('data error');
});
});
$scope.user = data.data;
}, function(data, status, headers, config) {
console.log('data error');
});
$http.get(urlapi + 'users/id/likes/' + $routeParams.userid)
.then(function(data, status, headers, config) {
console.log('data success');
console.log(data);
$scope.likes = data.data;
$scope.$broadcast('scroll.refreshComplete'); //refresher stop
}, function(data, status, headers, config) {
console.log('data error');
$scope.$broadcast('scroll.refreshComplete'); //refresher stop
});
});

Loading…
Cancel
Save