Skip to content

Instantly share code, notes, and snippets.

@agungyuliaji
Created March 23, 2016 06:13
Show Gist options
  • Save agungyuliaji/937f4f5a07d3f6b3b1fe to your computer and use it in GitHub Desktop.
Save agungyuliaji/937f4f5a07d3f6b3b1fe to your computer and use it in GitHub Desktop.
var schedulesControllers = angular.module('schedulesControllers', []);
schedulesControllers.controller('weekControllers', function($scope, $ionicHistory, $ionicLoading, schedulesService, $ionicSlideBoxDelegate, $interval, $filter, $state) {
$ionicLoading.show({
content: 'Loading',
animation: 'fade-in',
showBackdrop: true,
maxWidth: 200,
showDelay: 0
});
$scope.goBack = function() {
// $ionicHistory.goBack();
$ionicHistory.nextViewOptions({
disableBack: true
})
$state.go('cashier.desktop_app_menu');
}
var toUTCDate = function(date){
var _utc = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
return _utc;
};
var millisToUTCDate = function(millis){
return toUTCDate(new Date(millis));
};
var millisToUTCDateConvert = function(millis){
var timeC = $filter('date')(toUTCDate(new Date(millis)), 'a')
// return angular.lowercase(timeC.charAt(0))
return angular.lowercase(timeC.toString().charAt(0))
};
$scope.millisToUTCDateConvert = millisToUTCDateConvert;
$scope.toUTCDate = toUTCDate;
$scope.millisToUTCDate = millisToUTCDate;
$scope.class_file = "'loc-GDN': mySchedule.schedules[0].location === 'GDN','loc-FTD': mySchedule.schedules[0].location === 'FTD', 'loc-SCO': mySchedule.schedules[0].location === 'SCO', 'loc-PRO': mySchedule.schedules[0].location === 'PRO', 'loc-HCR': mySchedule.schedules[0].location === 'HCR', 'loc-FES': mySchedule.schedules[0].location === 'FES', 'loc-LOT': mySchedule.schedules[0].location === 'LOT', 'loc-BUC': mySchedule.schedules[0].location === 'BUC', 'loc-RTN': mySchedule.schedules[0].location === 'RTN'"
schedulesService.getMySchedule().then(function(response){
var scheds = response.schedule
var keys = Object.keys(scheds)
var i, len = keys.length;
keys.sort();
console.log("keys.sort()");
console.log(keys.sort());
mySchedules =[];
for (i = 0; i < len; i++) {
k = keys[i];
// alert(k + ':' + myObj[k]);
mySchedules.push(scheds[k]);
// console.log(scheds[k])
}
$scope.mySchedules = mySchedules;
// console.log("$scope.mySchedulesas")
// console.log($scope.mySchedulesas)
// $scope.mySchedules = response.schedule
// $scope.mySchedules = response.schedule
$scope.user = response.user;
console.log(response);
$scope.weekKeys = Object.keys(response.schedule).sort();
console.log(Object.keys(response.schedule));
window.localStorage['current_week'] = $scope.weekKeys.indexOf(response.current_week);
window.localStorage['daily_schedule'] = JSON.stringify(response.schedule);
$ionicSlideBoxDelegate.update();
console.log("schedule")
console.log(response.schedule)
$ionicLoading.hide();
})
$scope.current_week_index = window.localStorage['current_week']
})
schedulesControllers.controller('dayControllers', function($scope, $ionicHistory, $ionicLoading, schedulesService, $stateParams, $ionicSlideBoxDelegate) {
$ionicLoading.show({
content: 'Loading',
animation: 'fade-in',
showBackdrop: true,
maxWidth: 200,
showDelay: 0
});
var toUTCDate = function(date){
var _utc = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
return _utc;
};
var millisToUTCDate = function(millis){
return toUTCDate(new Date(millis));
};
$scope.toUTCDate = toUTCDate;
$scope.millisToUTCDate = millisToUTCDate;
$scope.goBack = function() {
$ionicHistory.goBack();
}
var all_week = window.localStorage['daily_schedule']
var day = JSON.parse(all_week)
var workDay = []
var getWorkDay = day[$stateParams.week]
for (var i = 0; i < getWorkDay.length; i++) {
if (getWorkDay[i].type != "off") {
workDay.push(getWorkDay[i])
}
};
$scope.dailySchedule = workDay
$scope.first_name = window.localStorage['first_name']
$scope.last_name = window.localStorage['last_name']
$ionicSlideBoxDelegate.update();
$ionicLoading.hide();
})
var scheduleServices = angular.module('scheduleServices', []);
scheduleServices.factory('schedulesService', function($http, $q) {
return {
getMySchedule: function() {
var deferred = $q.defer();
var startTime = new Date().getTime();
var id = window.localStorage['id_user']
$http.get("http://" + domainTarget + "/user_schedules/user_schedule/" + id + ".json", {headers: {"X-User-Email" : window.localStorage['email'], "X-User-Token" : window.localStorage['authentication_token']}})
.success(function(stores) {
deferred.resolve(stores)
})
return deferred.promise
},
getListUser: function() {
var deferred = $q.defer();
var startTime = new Date().getTime();
$http.get("http://" + domainTarget + "/user_schedules/associates_verified.json?store_id=" + window.localStorage['store'], {headers: {"X-User-Email" : window.localStorage['email'], "X-User-Token" : window.localStorage['authentication_token']}})
.success(function(stores) {
deferred.resolve(stores)
})
return deferred.promise
},
searchUser: function(userInputString) {
var deferred = $q.defer();
var startTime = new Date().getTime();
$http.get("http://" + domainTarget + "/user_schedules/search_associates_verified.json?q="+userInputString, {headers: {"X-User-Email" : window.localStorage['email'], "X-User-Token" : window.localStorage['authentication_token']}})
.success(function(response) {
deferred.resolve(response)
})
return deferred.promise
},
addSchedule: function(params, date) {
var deferred = $q.defer();
var startTime = new Date().getTime();
var fd = new FormData();
fd.append("schedule[user_id]", params.associates_name_bind);
fd.append("schedule[location]", params.Department);
fd.append("schedule[date]", date);
fd.append("schedule[shift_start]", date + " " + params.shift_start_hr + ":" + params.shift_start_mn + "" + params.shift_start_tm);
fd.append("schedule[shift_end]", date + " " + params.shift_end_hr + ":" + params.shift_end_mn + "" + params.shift_end_tm);
fd.append("schedule[lunch_start]", date + " " + params.lunch_start_hr + ":" + params.lunch_start_mn + "" + params.lunch_start_tm);
fd.append("schedule[lunch_end]", date + " " + params.lunch_end_hr + ":" + params.lunch_end_mn + "" + params.lunch_end_tm);
fd.append("schedule[break_one_start]", date + " " + params.break_1_start_hr + ":" + params.break_1_start_mn + "" + params.break_1_start_tm);
fd.append("schedule[break_one_end]", date + " " + params.break_1_end_hr + ":" + params.break_1_end_mn + "" + params.break_1_end_tm);
fd.append("schedule[break_two_start]", date + " " + params.break_2_start_hr + ":" + params.break_2_start_mn + "" + params.break_2_start_tm);
fd.append("schedule[break_two_end]", date + " " + params.break_2_end_hr + ":" + params.break_2_end_mn + "" + params.break_2_end_tm);
fd.append("schedule[other_one_start]", date + " " + params.other_1_start_hr + ":" + params.other_1_start_mn + "" + params.other_1_start_tm);
fd.append("schedule[other_one_end]", date + " " + params.other_1_end_hr + ":" + params.other_1_end_mn + "" + params.other_1_end_tm);
fd.append("schedule[other_two_start]", date + " " + params.other_2_start_hr + ":" + params.other_2_start_mn + "" + params.other_2_start_tm);
fd.append("schedule[other_two_end]", date + " " + params.other_2_end_hr + ":" + params.other_2_end_mn + "" + params.other_2_end_tm);
fd.append("schedule[other_three_start]", date + " " + params.other_3_start_hr + ":" + params.other_3_start_mn + "" + params.other_3_start_tm);
fd.append("schedule[other_three_end]", date + " " + params.other_3_end_hr + ":" + params.other_3_end_mn + "" + params.other_3_end_tm);
fd.append("schedule[other_four_start]", date + " " + params.other_4_start_hr + ":" + params.other_4_start_mn + "" + params.other_4_start_tm);
fd.append("schedule[other_four_end]", date + " " + params.other_4_end_hr + ":" + params.other_4_end_mn + "" + params.other_4_end_tm);
fd.append("schedule[other_one_location]", params.other_1_Department);
fd.append("schedule[other_two_location]", params.other_2_Department);
fd.append("schedule[other_three_location]", params.other_3_Department);
fd.append("schedule[other_four_location]", params.other_4_Department);
$http.post("http://" + domainTarget + "/schedules.json", fd, {withCredentials : false, headers : {
'Content-Type' : undefined,
"X-User-Email" : window.localStorage['email'],
"X-User-Token" : window.localStorage['authentication_token']
},
transformRequest : angular.identity})
.success(function(response) {
console.log(response)
deferred.resolve(response)
})
return deferred.promise
},
getUserSchedule: function(params) {
var deferred = $q.defer();
var startTime = new Date().getTime();
$http.get("http://" + domainTarget + "/schedules/" + params + ".json", {headers: {"X-User-Email" : window.localStorage['email'], "X-User-Token" : window.localStorage['authentication_token']}})
.success(function(stores) {
deferred.resolve(stores)
})
return deferred.promise
},
editSchedule: function(params, id) {
console.log("service");
console.log(params);
console.log(new Date());
console.log("================");
var deferred = $q.defer();
var startTime = new Date().getTime();
var fd = new FormData();
fd.append("schedule[location]", params.Department);
fd.append("schedule[shift_start]", params.shift_start_hr + ":" + params.shift_start_mn + "" + params.shift_start_tm);
fd.append("schedule[shift_end]", params.shift_end_hr + ":" + params.shift_end_mn + "" + params.shift_end_tm);
fd.append("schedule[lunch_start]", params.lunch_start_hr + ":" + params.lunch_start_mn + "" + params.lunch_start_tm);
fd.append("schedule[lunch_end]", params.lunch_end_hr + ":" + params.lunch_end_mn + "" + params.lunch_end_tm);
fd.append("schedule[break_one_start]", params.break_1_start_hr + ":" + params.break_1_start_mn + "" + params.break_1_start_tm);
fd.append("schedule[break_one_end]", params.break_1_end_hr + ":" + params.break_1_end_mn + "" + params.break_1_end_tm);
fd.append("schedule[break_two_start]", params.break_2_start_hr + ":" + params.break_2_start_mn + "" + params.break_2_start_tm);
fd.append("schedule[break_two_end]", params.break_2_end_hr + ":" + params.break_2_end_mn + "" + params.break_2_end_tm);
fd.append("schedule[other_one_start]", params.other_1_start_hr + ":" + params.other_1_start_mn + "" + params.other_1_start_tm);
fd.append("schedule[other_one_end]", params.other_1_end_hr + ":" + params.other_1_end_mn + "" + params.other_1_end_tm);
fd.append("schedule[other_two_start]", params.other_2_start_hr + ":" + params.other_2_start_mn + "" + params.other_2_start_tm);
fd.append("schedule[other_two_end]", params.other_2_end_hr + ":" + params.other_2_end_mn + "" + params.other_2_end_tm);
fd.append("schedule[other_three_start]", params.other_3_start_hr + ":" + params.other_3_start_mn + "" + params.other_3_start_tm);
fd.append("schedule[other_three_end]", params.other_3_end_hr + ":" + params.other_3_end_mn + "" + params.other_3_end_tm);
fd.append("schedule[other_four_start]", params.other_4_start_hr + ":" + params.other_4_start_mn + "" + params.other_4_start_tm);
fd.append("schedule[other_four_end]", params.other_4_end_hr + ":" + params.other_4_end_mn + "" + params.other_4_end_tm);
fd.append("schedule[other_one_location]", params.other_1_Department);
fd.append("schedule[other_two_location]", params.other_2_Department);
fd.append("schedule[other_three_location]", params.other_3_Department);
fd.append("schedule[other_four_location]", params.other_4_Department);
$http.patch("http://" + domainTarget + "/schedules/" + id + ".json", fd, {withCredentials : false, headers : {
'Content-Type' : undefined,
"X-User-Email" : window.localStorage['email'],
"X-User-Token" : window.localStorage['authentication_token']
},
transformRequest : angular.identity})
.success(function(response) {
console.log(response)
deferred.resolve(response)
})
return deferred.promise
},
deleteSchedule: function(params) {
var deferred = $q.defer();
var startTime = new Date().getTime();
console.log(window.localStorage['email'])
console.log(window.localStorage['authentication_token'])
$http.delete("http://" + domainTarget + "/schedules/" + params + ".json", {headers: {"X-User-Email" : window.localStorage['email'], "X-User-Token" : window.localStorage['authentication_token']}})
.success(function(stores) {
deferred.resolve(stores)
})
return deferred.promise
},
nts: function(id, nts) {
var deferred = $q.defer();
var startTime = new Date().getTime();
var fd = new FormData();
fd.append("schedule[id]", id);
fd.append("schedule[nts]", nts);
$http.post("http://" + domainTarget + "/schedules_nts/nts.json", fd, {withCredentials : false, headers : {
'Content-Type' : undefined,
"X-User-Email" : window.localStorage['email'],
"X-User-Token" : window.localStorage['authentication_token']
},
transformRequest : angular.identity})
.success(function(stores) {
deferred.resolve(stores)
})
return deferred.promise
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment