Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app=angular.module('todo', ['ionic', '$actionButton','ngCordova', 'chart.js']);
- app.config(function($stateProvider, $urlRouterProvider) {
- $stateProvider
- .state('login', {
- url: '/login',
- controller: 'loginctrl',
- templateUrl: 'login.html'
- });
- $stateProvider
- .state('home', {
- url: '/home',
- controller: 'homectrl',
- templateUrl: 'home.html'
- });
- $stateProvider
- .state('googlemap', {
- url: '/googlemap',
- controller: 'googlemapctrl',
- templateUrl: 'googlemap.html'
- });
- $stateProvider
- .state('users', {
- url: '/users',
- controller: 'usersctrl',
- templateUrl: 'users.html'
- });
- $stateProvider
- .state('chart', {
- url: '/chart',
- controller: 'chartctrl',
- templateUrl: 'chart.html'
- });
- $urlRouterProvider.otherwise('/chart');
- });
- app.controller('loginctrl', function($scope, $state,$ionicSideMenuDelegate,$http) {
- $scope.validatelogin = function (user) {
- $http.post('http://172.19.118.53/angularjs/script/login.php', {
- user: user
- })
- .then(function success(e) {
- if(e.data.status=="true")
- {
- $state.go("home",{});
- }
- else
- {
- alert("not good");
- }
- $scope.errors = [];
- //$scope.users.push(e.data.user);
- }, function error(e) {
- $scope.errors = e.data.errors;
- alert(e);
- });
- };
- $ionicSideMenuDelegate.canDragContent(false);
- });
- app.controller('homectrl',function($scope,$ionicModal,$http, $actionButton,$ionicSideMenuDelegate){
- $scope.openMenuLeft = function() {
- $ionicSideMenuDelegate.toggleLeft();
- };
- });
- app.controller('usersctrl',function($scope,$ionicModal,$http, $actionButton,$ionicSideMenuDelegate){
- $scope.openMenuLeft = function() {
- $ionicSideMenuDelegate.toggleLeft();
- };
- $scope.$on('$ionicView.enter', function(){
- var actionButton = $actionButton.create({
- mainAction: {
- icon: 'ion-android-create',
- backgroundColor: 'blue',
- textColor: ' white',
- onClick: function() {
- $scope.opennewusermodal();
- }
- }
- })
- });
- $scope.users = [];
- $scope.listusers = function () {
- $http.get('http://172.19.118.53/angularjs/script/list.php', {})
- .then(function success(e) {
- $scope.users = e.data.users;
- }, function error(e) {
- });
- };
- $scope.listusers();
- $scope.adduser = function (user) {
- $http.post('http://172.19.118.53/angularjs/script/create.php', {
- user: user
- })
- .then(function success(e) {
- $scope.errors = [];
- $scope.users.push(e.data.user);
- user.username="";
- user.password="";
- user.fullname="";
- }, function error(e) {
- $scope.errors = e.data.errors;
- });
- $scope.newusermodal.hide();
- };
- $scope.edit = function (index) {
- $scope.task_row = index;
- $scope.user_details = $scope.users[index];
- $scope.editusermodal.show();
- };
- $scope.edituser = function () {
- $http.post('http://172.19.118.53/angularjs/script/update.php', {
- user: $scope.user_details
- })
- .then(function success(e) {
- $scope.errors = [];
- $scope.editusermodal.hide();
- }, function error(e) {
- $scope.errors = e.data.errors;
- });
- };
- $scope.delete = function () {
- var conf = confirm("Do you really want to delete the task?");
- if (conf == true) {
- $http.post('http://172.19.118.53/angularjs/script/delete.php', {
- task: $scope.task_details
- })
- .then(function success(e) {
- $scope.errors = [];
- $scope.tasks.splice($scope.task_row, 1);
- $scope.userTask.hide();
- }, function error(e) {
- $scope.errors = e.data.errors;
- });
- }
- };
- //create and load the modal
- $ionicModal.fromTemplateUrl('newuser.html',function(modal){
- $scope.newusermodal=modal;
- },{scope:$scope,animation:'slide-in-up'
- });
- $ionicModal.fromTemplateUrl('edituser.html',function(modal){
- $scope.editusermodal=modal;
- },{scope:$scope,animation:'slide-in-up'
- });
- //function to show modal for new user insertion
- $scope.opennewusermodal=function(){
- $scope.newusermodal.show();
- };
- //function to hide the modal used for insertion
- $scope.closenewusermodal=function(){
- $scope.newusermodal.hide();
- };
- //function to hide the modal user for user editing
- $scope.closeeditusermodal=function(){
- $scope.editusermodal.hide();
- };
- //
- $scope.createTask=function(task){
- $scope.tasks.push({title:task.title});
- $scope.taskModal.hide();
- task.title="";
- };
- })
- app.controller('chartctrl',function($scope,$ionicModal,$http,$ionicSideMenuDelegate) {
- $scope.getyearsales = function (user) {
- $http.post('http://172.19.118.53/angularjs/script/getyearsales.php', {
- //user: user
- })
- .then(function success(e) {
- if(e.data.status=="true")
- {
- $scope.labels = e.data.year;
- $scope.series = ['Series A'];
- $scope.data =e.data.amount;
- $scope.onClick = function (points, evt) {
- console.log(points, evt);
- $scope.datasetOverride = [{ yAxisID: 'y-axis-1' }, { yAxisID: 'y-axis-2' }];
- $scope.options = {
- scales: {
- yAxes: [
- {
- id: 'y-axis-1',
- type: 'linear',
- display: true,
- position: 'left'
- },
- {
- id: 'y-axis-2',
- type: 'linear',
- display: true,
- position: 'right'
- }
- ]}
- };
- };
- }
- else
- {
- alert("not good");
- }
- $scope.errors = [];
- }, function error(e) {
- $scope.errors = e.data.errors;
- alert(e);
- });
- };
- $scope.getyearsales();
- $scope.openMenuLeft = function() {
- $ionicSideMenuDelegate.toggleLeft();
- };
- })
- app.controller('MainCtrl', function($scope, $ionicSideMenuDelegate,) {
- $scope.attendees = [
- { firstname: 'Nicolas', lastname: 'Cage' },
- { firstname: 'Jean-Claude', lastname: 'Van Damme' },
- { firstname: 'Keanu', lastname: 'Reeves' },
- { firstname: 'Steven', lastname: 'Seagal' }
- ];
- $scope.toggleLeft = function() {
- $ionicSideMenuDelegate.toggleLeft();
- };
- })
- app.controller('googlemapctrl', function($scope,$cordovaGeolocation) {
- $scope.showForm = true;
- var options = {timeout: 10000, enableHighAccuracy: true};
- $cordovaGeolocation.getCurrentPosition(options).then(function(position){
- var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
- var mapOptions = {
- center: latLng,
- zoom: 15,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
- //Wait until the map is loaded
- google.maps.event.addListenerOnce($scope.map, 'idle', function(){
- var marker = new google.maps.Marker({
- map: $scope.map,
- animation: google.maps.Animation.DROP,
- position: latLng
- });
- var infoWindow = new google.maps.InfoWindow({
- content: "Here I am!"
- });
- google.maps.event.addListener(marker, 'click', function () {
- infoWindow.open($scope.map, marker);
- });
- });
- }, function(error){
- console.log("Could not get location");
- });
- })
- app.controller('cameractrl', function ($scope, $cordovaCamera, $cordovaFile, $cordovaFileTransfer, $cordovaDevice, $ionicPopup, $ionicActionSheet) {
- $scope.image = null;
- $scope.showAlert = function(title, msg) {
- var alertPopup = $ionicPopup.alert({
- title: title,
- template: msg
- });
- };
- $scope.loadImage = function() {
- var options = {
- title: 'Select Image Source',
- buttonLabels: ['Load from Library', 'Use Camera'],
- addCancelButtonWithLabel: 'Cancel',
- androidEnableCancelButton : true,
- };
- $ionicActionSheet.show({
- buttons: [
- { text: 'Load from Library' },
- { text: 'Use Camera' }
- ],
- titleText: 'Select Image Source',
- cancelText: 'Cancel',
- cancel: function() {
- // add cancel code...
- },
- buttonClicked: function(index) {
- var type = null;
- if(index === 0) {
- type = Camera.PictureSourceType.PHOTOLIBRARY;
- }
- if(index === 1) {
- type = Camera.PictureSourceType.CAMERA;
- }
- if (type !== null)
- {
- $scope.selectPicture(type);
- }
- },
- destructiveButtonClicked: function() {
- // add delete code..
- }
- });
- };
- $scope.selectPicture = function(sourceType) {
- var options = {
- quality: 100,
- destinationType: Camera.DestinationType.FILE_URI,
- sourceType: sourceType,
- saveToPhotoAlbum: false
- };
- $cordovaCamera.getPicture(options).then(function(imagePath) {
- // Grab the file name of the photo in the temporary directory
- var currentName = imagePath.replace(/^.*[\\\/]/, '');
- //Create a new name for the photo
- var d = new Date(),
- n = d.getTime(),
- newFileName = n + ".jpg";
- // If you are trying to load image from the gallery on Android we need special treatment!
- if ($cordovaDevice.getPlatform() == 'Android' && sourceType === Camera.PictureSourceType.PHOTOLIBRARY) {
- window.FilePath.resolveNativePath(imagePath, function(entry) {
- window.resolveLocalFileSystemURL(entry, success, fail);
- function fail(e) {
- console.error('Error: ', e);
- }
- function success(fileEntry) {
- var namePath = fileEntry.nativeURL.substr(0, fileEntry.nativeURL.lastIndexOf('/') + 1);
- // Only copy because of access rights
- $cordovaFile.copyFile(namePath, fileEntry.name, cordova.file.dataDirectory, newFileName).then(function(success){
- $scope.image = newFileName;
- }, function(error){
- $scope.showAlert('Error', error.exception);
- });
- };
- }
- );
- } else {
- var namePath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
- // Move the file to permanent storage
- $cordovaFile.moveFile(namePath, currentName, cordova.file.dataDirectory, newFileName).then(function(success){
- $scope.image = newFileName;
- }, function(error){
- $scope.showAlert('Error', error.exception);
- });
- }
- },
- function(err){
- // Not always an error, maybe cancel was pressed...
- })
- };
- // Returns the local path inside the app for an image
- $scope.pathForImage = function(image) {
- if (image === null) {
- return '';
- } else {
- return cordova.file.dataDirectory + image;
- }
- };
- $scope.uploadImage = function() {
- // Destination URL
- var url = "http://172.19.118.53/angularjs/script/upload.php";
- // File for Upload
- var targetPath = $scope.pathForImage($scope.image);
- alert(targetPath);
- // File name only
- var filename = $scope.image;;
- var options = {
- fileKey: "file",
- fileName: filename,
- chunkedMode: false,
- mimeType: "multipart/form-data",
- params : {'fileName': filename}
- };
- $cordovaFileTransfer.upload(url, targetPath, options).then(function(result) {
- alert(result.responseCode);
- alert(result.response);
- alert(result.headers);
- $scope.showAlert('Success', 'Image upload finished.');
- });
- }
- });
- <html ng-app="todo">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
- <title>Side Menus</title>
- <link href="lib/ionic/css/ionic.css" rel="stylesheet">
- <link href="css/style.css" rel="stylesheet">
- <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
- <link href="css/ionic.app.css" rel="stylesheet">
- -->
- <!-- ionic/angularjs js -->
- <script src="lib/ionic/js/ionic.bundle.js"></script>
- <!-- cordova script (this will be a 404 during development) -->
- <script src="cordova.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/ng-cordova/0.1.27-alpha/ng-cordova.js"></script>
- <!-- your app's js -->
- <script src="js/app.js"></script>
- <script src="http://maps.google.com/maps/api/js?key=AIzaSyAqc8z_WaxxPh5a-Ey0twCi33onQxmg5Vk"></script>
- <link href="https://fmtoffolo.github.io/action-button/ion-action-button.css" rel="stylesheet">
- <script src="https://fmtoffolo.github.io/action-button/ion-action-button.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script>
- </head>
- <body ng-controller="homectrl">
- <script id="chart.html" type="text/ng-template">
- <ion-view title="Home">
- <ion-nav-buttons side="left">
- <button class="button button-icon button-clear ion-navicon" ng-click="openMenuLeft()"></button>
- </ion-nav-buttons>
- <ion-content padding="true">
- <h1 style="text-align: center;">Charting</h1>
- <canvas id="line" class="chart chart-line" chart-data="data"
- chart-labels="labels" chart-series="series" chart-options="options"
- chart-dataset-override="datasetOverride" chart-click="onClick">
- </canvas>
- </ion-content>
- </ion-view>
- </script>
- <script id="login.html" type="text/ng-template">
- <ion-view class="view-bg-blue" hide-nav-bar="true" >
- <ion-nav-buttons side="left">
- <button class="button button-icon button-clear ion-navicon" ng-click="openMenu()"></button>
- </ion-nav-buttons>
- <ion-content padding="true">
- <form ng-submit="validatelogin(user)">
- <h3 class="text-center">Welcome To Landing Page</h3>
- <div class="row">
- <div class="col">
- <div class="text-center">
- <h4>My App</h4>
- <div class="row">
- <div class="col">
- <input placeholder="User" ng-model="user.username">
- </div>
- </div>
- <div class="row">
- <div class="col">
- <input placeholder="password"ng-model="user.password">
- </div>
- </div>
- <div class="padding">
- <button type="submit" class="button button-block button-positive">Create User</button>
- </div>
- </div>
- </div>
- </div>
- </form>
- </ion-content>
- </ion-view>
- </script>
- <ion-side-menus>
- <ion-pane ion-side-menu-content>
- <ion-nav-bar class="bar-positive" ng-class="{'bar-custom' : headerChangeColor}">
- <ion-nav-buttons side="left">
- <button class="button button-icon button-clear ion-navicon" menu-toggle="left">
- </button>
- </ion-nav-buttons>
- </ion-nav-bar>
- <ion-nav-view animation="slide-left-right"></ion-nav-view>
- </ion-pane>
- <ion-side-menu side="left">
- <ion-header-bar class="bar-positive">
- <h1 class="title">user</h1>
- </ion-header-bar>
- <ion-content has-header="true" class="menu-right-border">
- <div class="list">
- <a href="#home" class="item" menu-close>Home</a>
- <a href="#users" class="item" menu-close>Users</a>
- <a href="#googlemap" class="item" menu-close>Google Map</a>
- <a href="#login" class="item" menu-close>Logout</a>
- <a href="#chart" class="item" menu-close>Chart</a>
- </div>
- </ion-content>
- </ion-side-menu>
- </ion-side-menus>
- <script id="home.html" type="text/ng-template">
- <ion-view title="Home">
- <ion-nav-buttons side="left">
- <button class="button button-icon button-clear ion-navicon" ng-click="openMenuLeft()"></button>
- </ion-nav-buttons>
- <ion-content padding="true">
- <h1 style="text-align: center;">Home Page</h1>
- </ion-content>
- </ion-view>
- </script>
- <script id="users.html" type="text/ng-template">
- <ion-view view-title="Welcome">
- <ion-nav-buttons side="left">
- <button class="button button-icon button-clear ion-navicon" ng-click="openMenuLeft()"></button>
- </ion-nav-buttons>
- <ion-content>
- <ion-list>
- <ion-item ng-repeat="user in users" href="" ng-click="edit($index)">
- {{user.fullname}}
- </ion-item>
- </ion-list>
- </ion-content>
- </ion-view>
- </script>
- <script id="googlemap.html" type="text/ng-template">
- <ion-view>
- <ion-content>
- <div id="map" data-tap-disabled="true"></div>
- </ion-content>
- </ion-view>
- </script>
- <script id="camera.html" type="text/ng-template">
- <ion-pane>
- <ion-header-bar class="bar-positive">
- <h1 class="title">Devdactic Image Upload</h1>
- </ion-header-bar>
- <ion-content>
- <img ng-src="{{pathForImage(image)}}" style="width: 100%; height: 100%;">
- </ion-content>
- <ion-footer-bar class="bar bar-positive">
- <div class="button-bar">
- <button class="button icon-left ion-camera" ng-click="loadImage()">Take Photo</button>
- <button class="button icon-left ion-upload" ng-click="uploadImage()" ng-disabled="image === null">Upload</button>
- </div>
- </ion-footer-bar>
- </ion-pane>
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement