Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.40 KB | None | 0 0
  1. var app=angular.module('todo', ['ionic', '$actionButton','ngCordova', 'chart.js']);
  2.  
  3. app.config(function($stateProvider, $urlRouterProvider) {
  4. $stateProvider
  5. .state('login', {
  6. url: '/login',
  7. controller: 'loginctrl',
  8. templateUrl: 'login.html'
  9. });
  10. $stateProvider
  11. .state('home', {
  12. url: '/home',
  13. controller: 'homectrl',
  14. templateUrl: 'home.html'
  15. });
  16. $stateProvider
  17. .state('googlemap', {
  18. url: '/googlemap',
  19. controller: 'googlemapctrl',
  20. templateUrl: 'googlemap.html'
  21. });
  22. $stateProvider
  23. .state('users', {
  24. url: '/users',
  25. controller: 'usersctrl',
  26. templateUrl: 'users.html'
  27. });
  28. $stateProvider
  29. .state('chart', {
  30. url: '/chart',
  31. controller: 'chartctrl',
  32. templateUrl: 'chart.html'
  33. });
  34. $urlRouterProvider.otherwise('/chart');
  35. });
  36. app.controller('loginctrl', function($scope, $state,$ionicSideMenuDelegate,$http) {
  37. $scope.validatelogin = function (user) {
  38. $http.post('http://172.19.118.53/angularjs/script/login.php', {
  39. user: user
  40. })
  41. .then(function success(e) {
  42. if(e.data.status=="true")
  43. {
  44. $state.go("home",{});
  45. }
  46. else
  47. {
  48. alert("not good");
  49. }
  50. $scope.errors = [];
  51. //$scope.users.push(e.data.user);
  52. }, function error(e) {
  53. $scope.errors = e.data.errors;
  54. alert(e);
  55. });
  56. };
  57. $ionicSideMenuDelegate.canDragContent(false);
  58. });
  59. app.controller('homectrl',function($scope,$ionicModal,$http, $actionButton,$ionicSideMenuDelegate){
  60. $scope.openMenuLeft = function() {
  61. $ionicSideMenuDelegate.toggleLeft();
  62. };
  63. });
  64. app.controller('usersctrl',function($scope,$ionicModal,$http, $actionButton,$ionicSideMenuDelegate){
  65. $scope.openMenuLeft = function() {
  66. $ionicSideMenuDelegate.toggleLeft();
  67. };
  68. $scope.$on('$ionicView.enter', function(){
  69. var actionButton = $actionButton.create({
  70.  
  71. mainAction: {
  72. icon: 'ion-android-create',
  73. backgroundColor: 'blue',
  74. textColor: ' white',
  75. onClick: function() {
  76. $scope.opennewusermodal();
  77. }
  78. }
  79. })
  80. });
  81. $scope.users = [];
  82.  
  83. $scope.listusers = function () {
  84. $http.get('http://172.19.118.53/angularjs/script/list.php', {})
  85. .then(function success(e) {
  86. $scope.users = e.data.users;
  87. }, function error(e) {
  88.  
  89. });
  90.  
  91. };
  92. $scope.listusers();
  93.  
  94. $scope.adduser = function (user) {
  95. $http.post('http://172.19.118.53/angularjs/script/create.php', {
  96. user: user
  97. })
  98. .then(function success(e) {
  99.  
  100. $scope.errors = [];
  101.  
  102. $scope.users.push(e.data.user);
  103.  
  104. user.username="";
  105. user.password="";
  106. user.fullname="";
  107.  
  108. }, function error(e) {
  109. $scope.errors = e.data.errors;
  110. });
  111. $scope.newusermodal.hide();
  112. };
  113. $scope.edit = function (index) {
  114. $scope.task_row = index;
  115. $scope.user_details = $scope.users[index];
  116. $scope.editusermodal.show();
  117. };
  118. $scope.edituser = function () {
  119. $http.post('http://172.19.118.53/angularjs/script/update.php', {
  120. user: $scope.user_details
  121. })
  122. .then(function success(e) {
  123. $scope.errors = [];
  124. $scope.editusermodal.hide();
  125. }, function error(e) {
  126. $scope.errors = e.data.errors;
  127. });
  128.  
  129. };
  130.  
  131. $scope.delete = function () {
  132. var conf = confirm("Do you really want to delete the task?");
  133.  
  134. if (conf == true) {
  135. $http.post('http://172.19.118.53/angularjs/script/delete.php', {
  136. task: $scope.task_details
  137. })
  138.  
  139. .then(function success(e) {
  140. $scope.errors = [];
  141.  
  142. $scope.tasks.splice($scope.task_row, 1);
  143. $scope.userTask.hide();
  144. }, function error(e) {
  145. $scope.errors = e.data.errors;
  146. });
  147. }
  148. };
  149.  
  150. //create and load the modal
  151. $ionicModal.fromTemplateUrl('newuser.html',function(modal){
  152. $scope.newusermodal=modal;
  153. },{scope:$scope,animation:'slide-in-up'
  154. });
  155.  
  156. $ionicModal.fromTemplateUrl('edituser.html',function(modal){
  157. $scope.editusermodal=modal;
  158. },{scope:$scope,animation:'slide-in-up'
  159. });
  160.  
  161. //function to show modal for new user insertion
  162. $scope.opennewusermodal=function(){
  163. $scope.newusermodal.show();
  164. };
  165.  
  166. //function to hide the modal used for insertion
  167. $scope.closenewusermodal=function(){
  168. $scope.newusermodal.hide();
  169. };
  170.  
  171. //function to hide the modal user for user editing
  172. $scope.closeeditusermodal=function(){
  173. $scope.editusermodal.hide();
  174. };
  175.  
  176.  
  177. //
  178. $scope.createTask=function(task){
  179. $scope.tasks.push({title:task.title});
  180. $scope.taskModal.hide();
  181. task.title="";
  182. };
  183. })
  184. app.controller('chartctrl',function($scope,$ionicModal,$http,$ionicSideMenuDelegate) {
  185. $scope.getyearsales = function (user) {
  186. $http.post('http://172.19.118.53/angularjs/script/getyearsales.php', {
  187. //user: user
  188. })
  189. .then(function success(e) {
  190. if(e.data.status=="true")
  191. {
  192. $scope.labels = e.data.year;
  193. $scope.series = ['Series A'];
  194. $scope.data =e.data.amount;
  195. $scope.onClick = function (points, evt) {
  196. console.log(points, evt);
  197. $scope.datasetOverride = [{ yAxisID: 'y-axis-1' }, { yAxisID: 'y-axis-2' }];
  198. $scope.options = {
  199. scales: {
  200. yAxes: [
  201. {
  202. id: 'y-axis-1',
  203. type: 'linear',
  204. display: true,
  205. position: 'left'
  206. },
  207. {
  208. id: 'y-axis-2',
  209. type: 'linear',
  210. display: true,
  211. position: 'right'
  212. }
  213. ]}
  214. };
  215. };
  216. }
  217. else
  218. {
  219. alert("not good");
  220. }
  221. $scope.errors = [];
  222. }, function error(e) {
  223. $scope.errors = e.data.errors;
  224. alert(e);
  225. });
  226. };
  227. $scope.getyearsales();
  228. $scope.openMenuLeft = function() {
  229. $ionicSideMenuDelegate.toggleLeft();
  230. };
  231. })
  232. app.controller('MainCtrl', function($scope, $ionicSideMenuDelegate,) {
  233. $scope.attendees = [
  234. { firstname: 'Nicolas', lastname: 'Cage' },
  235. { firstname: 'Jean-Claude', lastname: 'Van Damme' },
  236. { firstname: 'Keanu', lastname: 'Reeves' },
  237. { firstname: 'Steven', lastname: 'Seagal' }
  238. ];
  239.  
  240. $scope.toggleLeft = function() {
  241. $ionicSideMenuDelegate.toggleLeft();
  242. };
  243. })
  244.  
  245. app.controller('googlemapctrl', function($scope,$cordovaGeolocation) {
  246. $scope.showForm = true;
  247. var options = {timeout: 10000, enableHighAccuracy: true};
  248. $cordovaGeolocation.getCurrentPosition(options).then(function(position){
  249. var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
  250. var mapOptions = {
  251. center: latLng,
  252. zoom: 15,
  253. mapTypeId: google.maps.MapTypeId.ROADMAP
  254. };
  255. $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
  256. //Wait until the map is loaded
  257. google.maps.event.addListenerOnce($scope.map, 'idle', function(){
  258.  
  259. var marker = new google.maps.Marker({
  260. map: $scope.map,
  261. animation: google.maps.Animation.DROP,
  262. position: latLng
  263. });
  264. var infoWindow = new google.maps.InfoWindow({
  265. content: "Here I am!"
  266. });
  267.  
  268. google.maps.event.addListener(marker, 'click', function () {
  269. infoWindow.open($scope.map, marker);
  270. });
  271.  
  272. });
  273. }, function(error){
  274. console.log("Could not get location");
  275. });
  276.  
  277. })
  278. app.controller('cameractrl', function ($scope, $cordovaCamera, $cordovaFile, $cordovaFileTransfer, $cordovaDevice, $ionicPopup, $ionicActionSheet) {
  279. $scope.image = null;
  280.  
  281. $scope.showAlert = function(title, msg) {
  282. var alertPopup = $ionicPopup.alert({
  283. title: title,
  284. template: msg
  285. });
  286. };
  287. $scope.loadImage = function() {
  288. var options = {
  289. title: 'Select Image Source',
  290. buttonLabels: ['Load from Library', 'Use Camera'],
  291. addCancelButtonWithLabel: 'Cancel',
  292. androidEnableCancelButton : true,
  293. };
  294. $ionicActionSheet.show({
  295. buttons: [
  296. { text: 'Load from Library' },
  297. { text: 'Use Camera' }
  298. ],
  299. titleText: 'Select Image Source',
  300. cancelText: 'Cancel',
  301.  
  302. cancel: function() {
  303. // add cancel code...
  304. },
  305.  
  306. buttonClicked: function(index) {
  307. var type = null;
  308. if(index === 0) {
  309. type = Camera.PictureSourceType.PHOTOLIBRARY;
  310. }
  311.  
  312. if(index === 1) {
  313. type = Camera.PictureSourceType.CAMERA;
  314. }
  315. if (type !== null)
  316. {
  317. $scope.selectPicture(type);
  318. }
  319. },
  320.  
  321. destructiveButtonClicked: function() {
  322. // add delete code..
  323. }
  324. });
  325. };
  326.  
  327. $scope.selectPicture = function(sourceType) {
  328. var options = {
  329. quality: 100,
  330. destinationType: Camera.DestinationType.FILE_URI,
  331. sourceType: sourceType,
  332. saveToPhotoAlbum: false
  333. };
  334.  
  335. $cordovaCamera.getPicture(options).then(function(imagePath) {
  336. // Grab the file name of the photo in the temporary directory
  337. var currentName = imagePath.replace(/^.*[\\\/]/, '');
  338.  
  339. //Create a new name for the photo
  340. var d = new Date(),
  341. n = d.getTime(),
  342. newFileName = n + ".jpg";
  343.  
  344. // If you are trying to load image from the gallery on Android we need special treatment!
  345. if ($cordovaDevice.getPlatform() == 'Android' && sourceType === Camera.PictureSourceType.PHOTOLIBRARY) {
  346. window.FilePath.resolveNativePath(imagePath, function(entry) {
  347. window.resolveLocalFileSystemURL(entry, success, fail);
  348. function fail(e) {
  349. console.error('Error: ', e);
  350. }
  351.  
  352. function success(fileEntry) {
  353. var namePath = fileEntry.nativeURL.substr(0, fileEntry.nativeURL.lastIndexOf('/') + 1);
  354. // Only copy because of access rights
  355. $cordovaFile.copyFile(namePath, fileEntry.name, cordova.file.dataDirectory, newFileName).then(function(success){
  356. $scope.image = newFileName;
  357. }, function(error){
  358. $scope.showAlert('Error', error.exception);
  359. });
  360. };
  361. }
  362. );
  363. } else {
  364. var namePath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
  365. // Move the file to permanent storage
  366. $cordovaFile.moveFile(namePath, currentName, cordova.file.dataDirectory, newFileName).then(function(success){
  367. $scope.image = newFileName;
  368. }, function(error){
  369. $scope.showAlert('Error', error.exception);
  370. });
  371. }
  372. },
  373. function(err){
  374. // Not always an error, maybe cancel was pressed...
  375. })
  376. };
  377. // Returns the local path inside the app for an image
  378. $scope.pathForImage = function(image) {
  379. if (image === null) {
  380. return '';
  381. } else {
  382. return cordova.file.dataDirectory + image;
  383. }
  384. };
  385. $scope.uploadImage = function() {
  386. // Destination URL
  387. var url = "http://172.19.118.53/angularjs/script/upload.php";
  388.  
  389. // File for Upload
  390. var targetPath = $scope.pathForImage($scope.image);
  391. alert(targetPath);
  392.  
  393. // File name only
  394. var filename = $scope.image;;
  395.  
  396. var options = {
  397. fileKey: "file",
  398. fileName: filename,
  399. chunkedMode: false,
  400. mimeType: "multipart/form-data",
  401. params : {'fileName': filename}
  402. };
  403.  
  404. $cordovaFileTransfer.upload(url, targetPath, options).then(function(result) {
  405. alert(result.responseCode);
  406. alert(result.response);
  407. alert(result.headers);
  408. $scope.showAlert('Success', 'Image upload finished.');
  409. });
  410. }
  411. });
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421. <html ng-app="todo">
  422. <head>
  423. <meta charset="utf-8">
  424. <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
  425.  
  426. <title>Side Menus</title>
  427.  
  428. <link href="lib/ionic/css/ionic.css" rel="stylesheet">
  429. <link href="css/style.css" rel="stylesheet">
  430.  
  431. <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
  432. <link href="css/ionic.app.css" rel="stylesheet">
  433. -->
  434.  
  435. <!-- ionic/angularjs js -->
  436. <script src="lib/ionic/js/ionic.bundle.js"></script>
  437.  
  438. <!-- cordova script (this will be a 404 during development) -->
  439. <script src="cordova.js"></script>
  440.  
  441. <script src="https://cdnjs.cloudflare.com/ajax/libs/ng-cordova/0.1.27-alpha/ng-cordova.js"></script>
  442.  
  443. <!-- your app's js -->
  444. <script src="js/app.js"></script>
  445. <script src="http://maps.google.com/maps/api/js?key=AIzaSyAqc8z_WaxxPh5a-Ey0twCi33onQxmg5Vk"></script>
  446. <link href="https://fmtoffolo.github.io/action-button/ion-action-button.css" rel="stylesheet">
  447.  
  448. <script src="https://fmtoffolo.github.io/action-button/ion-action-button.js"></script>
  449. <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
  450. <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script>
  451.  
  452. </head>
  453.  
  454. <body ng-controller="homectrl">
  455.  
  456. <script id="chart.html" type="text/ng-template">
  457. <ion-view title="Home">
  458. <ion-nav-buttons side="left">
  459. <button class="button button-icon button-clear ion-navicon" ng-click="openMenuLeft()"></button>
  460. </ion-nav-buttons>
  461. <ion-content padding="true">
  462. <h1 style="text-align: center;">Charting</h1>
  463. <canvas id="line" class="chart chart-line" chart-data="data"
  464. chart-labels="labels" chart-series="series" chart-options="options"
  465. chart-dataset-override="datasetOverride" chart-click="onClick">
  466. </canvas>
  467. </ion-content>
  468. </ion-view>
  469. </script>
  470. <script id="login.html" type="text/ng-template">
  471. <ion-view class="view-bg-blue" hide-nav-bar="true" >
  472. <ion-nav-buttons side="left">
  473. <button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
  474. </ion-nav-buttons>
  475. <ion-content padding="true">
  476. <form ng-submit="validatelogin(user)">
  477. <h3 class="text-center">Welcome To Landing Page</h3>
  478. <div class="row">
  479. <div class="col">
  480. <div class="text-center">
  481. <h4>My App</h4>
  482. <div class="row">
  483. <div class="col">
  484. <input placeholder="User" ng-model="user.username">
  485. </div>
  486. </div>
  487. <div class="row">
  488. <div class="col">
  489. <input placeholder="password"ng-model="user.password">
  490. </div>
  491. </div>
  492. <div class="padding">
  493. <button type="submit" class="button button-block button-positive">Create User</button>
  494. </div>
  495. </div>
  496. </div>
  497. </div>
  498. </form>
  499. </ion-content>
  500. </ion-view>
  501. </script>
  502.  
  503. <ion-side-menus>
  504. <ion-pane ion-side-menu-content>
  505. <ion-nav-bar class="bar-positive" ng-class="{'bar-custom' : headerChangeColor}">
  506. <ion-nav-buttons side="left">
  507. <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
  508. </button>
  509. </ion-nav-buttons>
  510. </ion-nav-bar>
  511. <ion-nav-view animation="slide-left-right"></ion-nav-view>
  512. </ion-pane>
  513. <ion-side-menu side="left">
  514. <ion-header-bar class="bar-positive">
  515. <h1 class="title">user</h1>
  516. </ion-header-bar>
  517. <ion-content has-header="true" class="menu-right-border">
  518. <div class="list">
  519. <a href="#home" class="item" menu-close>Home</a>
  520. <a href="#users" class="item" menu-close>Users</a>
  521. <a href="#googlemap" class="item" menu-close>Google Map</a>
  522. <a href="#login" class="item" menu-close>Logout</a>
  523. <a href="#chart" class="item" menu-close>Chart</a>
  524. </div>
  525. </ion-content>
  526. </ion-side-menu>
  527.  
  528. </ion-side-menus>
  529.  
  530. <script id="home.html" type="text/ng-template">
  531. <ion-view title="Home">
  532. <ion-nav-buttons side="left">
  533. <button class="button button-icon button-clear ion-navicon" ng-click="openMenuLeft()"></button>
  534. </ion-nav-buttons>
  535. <ion-content padding="true">
  536. <h1 style="text-align: center;">Home Page</h1>
  537. </ion-content>
  538. </ion-view>
  539. </script>
  540.  
  541. <script id="users.html" type="text/ng-template">
  542. <ion-view view-title="Welcome">
  543. <ion-nav-buttons side="left">
  544. <button class="button button-icon button-clear ion-navicon" ng-click="openMenuLeft()"></button>
  545. </ion-nav-buttons>
  546. <ion-content>
  547. <ion-list>
  548. <ion-item ng-repeat="user in users" href="" ng-click="edit($index)">
  549. {{user.fullname}}
  550. </ion-item>
  551. </ion-list>
  552. </ion-content>
  553. </ion-view>
  554. </script>
  555.  
  556. <script id="googlemap.html" type="text/ng-template">
  557. <ion-view>
  558. <ion-content>
  559. <div id="map" data-tap-disabled="true"></div>
  560. </ion-content>
  561. </ion-view>
  562. </script>
  563.  
  564. <script id="camera.html" type="text/ng-template">
  565. <ion-pane>
  566. <ion-header-bar class="bar-positive">
  567. <h1 class="title">Devdactic Image Upload</h1>
  568. </ion-header-bar>
  569. <ion-content>
  570. <img ng-src="{{pathForImage(image)}}" style="width: 100%; height: 100%;">
  571. </ion-content>
  572. <ion-footer-bar class="bar bar-positive">
  573. <div class="button-bar">
  574. <button class="button icon-left ion-camera" ng-click="loadImage()">Take Photo</button>
  575. <button class="button icon-left ion-upload" ng-click="uploadImage()" ng-disabled="image === null">Upload</button>
  576. </div>
  577. </ion-footer-bar>
  578. </ion-pane>
  579. </script>
  580.  
  581.  
  582. </body>
  583. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement