Created
October 11, 2015 06:56
-
-
Save rbrahul/66c824a3ca956dcb7f0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myApp.config(function($stateProvider,$urlRouterProvider){ | |
$stateProvider.state('task', | |
{ | |
url:'/task', | |
controller:'TaskController', | |
views:{ | |
"sidebar":{templateUrl:'/partial/task/taskcreateform.html'}, | |
"content":{templateUrl:'/partial/task/taskgrid.html'} | |
}, | |
}) | |
.state('edittask', | |
{ | |
url:'/edittask/:editabletaskid', | |
controller:'TaskController', | |
views:{ | |
"sidebar":{templateUrl:'/partial/task/taskupdateform.html'}, | |
"content":{templateUrl:'/partial/task/taskgrid.html'} | |
}, | |
resolve:{ | |
'editabletask': function($stateParams,Task){ | |
Task.get({id:$stateParams.editabletaskid}, | |
function(response){ | |
return response; | |
}, | |
function(err){ | |
console.log(err); | |
}); | |
} | |
} | |
}); | |
$urlRouterProvider.otherwise('task'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myApp=angular.module("myApp",["ui.router","ngResource","ui.bootstrap.datetimepicker","toaster"]); | |
myApp.controller("TaskController",["$scope","$document","$filter","$interval","$timeout","$http","$httpParamSerializerJQLike", | |
"$stateParams","Task","toaster","editabletask", | |
function($scope,$document,$filter,$interval,$timeout,$http,$httpParamSerializerJQLike, | |
$stateParams,Task,toaster,editabletask){ | |
$scope.appname="Test App"; | |
$scope.task={date:null,status:'pending'}; | |
$scope.showToast=function(type,title,msg){ | |
toaster.pop(type,title,msg); | |
}; | |
$scope.startAlarm=function(){ | |
var tonenode=document.getElementById("audiorb"); | |
tonenode.play(); | |
console.log("he he"); | |
}; | |
$scope.stopAlarm=function(){ | |
var tonenode=document.getElementById("audiorb"); | |
tonenode.pause(); | |
tonenode.currentTime=0; | |
}; | |
var checktask; | |
$scope.checkingTask=function(){ | |
checktask=$interval( function(){ | |
var now=new Date() | |
$http({ | |
method:"GET", | |
url:'/checktask/', | |
params:{ | |
'date':$filter('date')(now,'yyyy-MM-dd HH:mm:ss') | |
}, | |
paramSerializer: '$httpParamSerializerJQLike' | |
}) | |
.then(function(response){ | |
if(response.data.task!=undefined){ | |
if(response.data.alarm=="1"){ | |
$scope.startAlarm(); | |
$timeout($scope.stopAlarm,20000); | |
} | |
$scope.showToast('success','Task Reminder',response.data.task); | |
$scope.getTask(); | |
} | |
}, | |
function(error){ | |
console.log(error); | |
}); | |
} | |
,10000); | |
}(); | |
$scope.stopChecking=function(){ | |
$interval.cancel(checktask); | |
}; | |
$scope.dummyTasks=[ | |
{task:"Watching Movie, 3 Idiots", task_at:"2015-10-06 10:09:00",status:"pending"}, | |
{task:"Playing Game, Army of Darkness", task_at:"2015-10-07 10:09:00",status:"pending"}, | |
{task:"Taking Break Fast, Army of Darkness", task_at:"2015-10-08 08:09:00",status:"done"}, | |
]; | |
$scope.storeTask=function(){ | |
var taskAt=$filter('date')($scope.task.date,'yyyy-MM-dd HH:mm:ss') | |
Task.save({task:$scope.task.taskname,task_at:taskAt,alarm:$scope.task.alarm},function(data){ | |
}); | |
$scope.getTask(); | |
}; | |
$scope.getTask=function(){ | |
Task.query(function(data){ | |
$scope.dummyTasks=data; | |
}); | |
}; | |
$scope.getTask(); | |
$scope.daleteableTaskId=null; | |
$scope.deteteTaskConfirmation=function(id){ | |
$scope.daleteableTaskId=id; | |
$(document).ready(function(){ | |
$('#myModal').modal('show'); | |
}); | |
}; | |
$scope.deleteTask=function(){ | |
Task.delete({id:$scope.daleteableTaskId},function(response){ | |
//response=angular.toJson(response); | |
console.log(response.msg); | |
if(response.msg!= undefined){ | |
$scope.showToast('success','Notification',response.msg); | |
$scope.getTask(); | |
$(document).ready(function(){ | |
$('#myModal').modal('hide'); | |
}); | |
} | |
}, | |
function(err){ | |
console.log(err); | |
}); | |
} | |
$scope.editableTaskId=null; | |
$scope.editTask=function(index){ | |
var task=$scope.dummyTasks[index]; | |
$scope.task.taskname=task.task; | |
$scope.task.alarm=task.alarm; | |
$scope.editableTaskId=task.id; | |
// console.log($scope.editableTaskId); | |
console.log(task.task_at); | |
var dateObj=$filter('parsedate')(task.task_at); | |
$scope.task.date=$filter('date')(dateObj,'EEE MMM dd yyyy HH:mm:ss') | |
}; | |
if($stateParams.editabletaskid){ | |
console.log($stateParams.editabletaskid); | |
$scope.editTask($stateParams.editabletaskid); | |
} | |
$scope.updateTask=function(){ | |
Task.update({id:$scope.editableTaskId},$scope.task,function(response){ | |
console.log(response); | |
},function(error){ | |
console.log(error); | |
}) | |
} | |
$scope.name="Rahul"; | |
console.log($scope.name); | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment