Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Persistent SqlLite data functions
- */
- /**
- * Will initialize the TouchParams (variables within the touch_params table)
- */
- $scope.initializeTouchParamVars = function () {
- var query = 'SELECT id, touchID, showTouchIDOption, touchLogin, showTouchLink FROM touch_params';
- $cordovaSQLite.execute(db, query).then(function (res) {
- if(res.rows.length > 0) {
- $scope.setTouchParamsVariables();
- $scope.viewTouchParams();
- } else {
- var initQuery = 'INSERT INTO touch_params (touchID, showTouchIDOption, touchLogin, showTouchLink) VALUES (?,?,?,?)';
- $cordovaSQLite.execute(db, initQuery, ['false', 'false', 'false', 'false']).then(function (res) {
- console.log('initializeTouchParamVars res: ', res);
- $scope.setTouchParamsVariables();
- $scope.viewTouchParams();
- },function (err) {
- console.log('initializeTouchParamVars error: ', err);
- })
- }
- },function (err) {
- console.log('initializeTouchParamVars err: ', err);
- });
- };
- /**
- * Will initialize the AuthParams (variables within the auth table)
- */
- $scope.initializeAuthParamVars = function () {
- var query = 'SELECT id, username, password, Authorization FROM auth';
- $cordovaSQLite.execute(db, query).then(function (res) {
- if(res.rows.length > 0) {
- $scope.setAuthVariables();
- $scope.viewAuth();
- } else {
- var initQuery = 'INSERT INTO auth (username, password, Authorization) VALUES (?,?,?)';
- $cordovaSQLite.execute(db, initQuery, ['null', 'null', 'null']).then(function (res) {
- console.log('initializeAuthParamVars res:', res);
- $scope.setAuthVariables();
- $scope.viewAuth();
- },function (err) {
- console.log('initializeAuthParamVars err:', err);
- })
- }
- }, function (err) {
- console.log('initializeAuthParamVars err:', err);
- })
- };
- /**
- * Will set the touch_param scope variables
- * to whatever is currently in the database
- */
- $scope.setTouchParamsVariables = function () {
- var query = 'SELECT id, touchID, showTouchIDOption, touchLogin, showTouchLink FROM touch_params';
- $cordovaSQLite.execute(db, query).then(function (res) {
- console.log('setTouchParamsVariables res', res.rows.item(0).showTouchIDOption);
- $scope.showTouchIDOption = $scope.textToDataTypeConverter(res.rows.item(0).showTouchIDOption);
- $scope.showTouchLink = $scope.textToDataTypeConverter(res.rows.item(0).showTouchLink);
- $scope.touchID = $scope.textToDataTypeConverter(res.rows.item(0).touchID);
- $scope.touchLogin = $scope.textToDataTypeConverter(res.rows.item(0).touchLogin);
- // alert($scope.showTouchIDOption);
- // alert($scope.showTouchLink);
- // alert($scope.touchID);
- // alert($scope.touchLogin);
- console.log('$scope.showTouchIDOption', $scope.showTouchIDOption);
- console.log('$scope.showTouchLink', $scope.showTouchLink);
- console.log('$scope.touchID', $scope.touchID);
- console.log('$scope.touchLogin', $scope.touchLogin);
- }, function (err) {
- alert(err);
- console.log('setTouchParamsVariables err', err);
- });
- };
- /**
- * Will set the auth scope variables
- * to whatever is currently in the database
- */
- $scope.setAuthVariables = function () {
- var query = 'SELECT id, username, password, Authorization FROM auth';
- $cordovaSQLite.execute(db, query).then(function (res) {
- $scope.username = $scope.textToDataTypeConverter(res.rows.item(0).username);
- $scope.password = $scope.textToDataTypeConverter(res.rows.item(0).password);
- $scope.Authorization = $scope.textToDataTypeConverter(res.rows.item(0).Authorization);
- console.log('setAuthVariables $scope.username:', $scope.username);
- console.log('setAuthVariables $scope.password:', $scope.password);
- console.log('setAuthVariables $scope.Authorization:', $scope.Authorization);
- },function (err) {
- console.log('setAuthVariables err:', err);
- });
- };
- /**
- * Will update the touchID column along with update the touchID scope variable
- * Note since this is only dealing with one user, we always want to update the
- * first entry
- */
- $scope.updateTouchID = function (touchID) {
- var query = 'UPDATE touch_params SET touchID=? WHERE id=1';
- var touchIDInput = $scope.dataTypeToTextConverter(touchID);
- $cordovaSQLite.execute(db, query, [touchIDInput]).then(function (res) {
- $scope.viewTouchParams();
- $scope.setTouchParamsVariables();
- }, function (err) {
- console.log('updateTouchID err', err);
- })
- };
- /**
- * Will update the touchLogin column along with update the touchLogin scope variable
- */
- $scope.updateTouchLogin = function (touchLogin) {
- var query = 'UPDATE touch_params SET touchLogin=? WHERE id=1';
- var touchLoginInput = $scope.dataTypeToTextConverter(touchLogin);
- $cordovaSQLite.execute(db, query, [touchLoginInput]).then(function (res) {
- $scope.viewTouchParams();
- $scope.setTouchParamsVariables();
- },function (err) {
- console.log('updateTouchLogin err', err)
- });
- };
- /**
- * Will update the showTouchIDOption column along with the showTouchIDOption scope variable
- */
- $scope.updateShowTouchIDOption = function (showTouchIDOption) {
- var query = 'UPDATE touch_params SET showTouchIDOption=? WHERE id=1';
- var showTouchIDOptionInput = $scope.dataTypeToTextConverter(showTouchIDOption);
- $cordovaSQLite.execute(db, query, [showTouchIDOptionInput]).then(function (res) {
- $scope.viewTouchParams();
- $scope.setTouchParamsVariables();
- },function (err) {
- console.log('updateShowTouchIDOption err', err)
- });
- };
- /**
- * Will update the showTouchLink column along with the showTouchLink scope variable
- */
- $scope.updateShowTouchLink = function (showTouchLink) {
- var query = 'UPDATE touch_params SET showTouchIDOption=? WHERE id=1';
- var showTouchLinkInput = $scope.dataTypeToTextConverter(showTouchLink);
- $cordovaSQLite.execute(db, query, [showTouchLinkInput]).then(function (res) {
- $scope.viewTouchParams();
- $scope.setTouchParamsVariables();
- },function (err) {
- console.log('updateShowTouchLink err', err)
- });
- };
- /**
- * Will update the username column along wiht the username scope variable
- */
- $scope.updateUsername = function (username) {
- var query = 'UPDATE auth SET username=? WHERE id=1';
- var usernameInput = $scope.dataTypeToTextConverter(username);
- $cordovaSQLite.execute(db, query, [usernameInput]).then(function (res) {
- $scope.viewAuth();
- $scope.setAuthVariables();
- },function (err) {
- console.log('updateUsername err', err);
- })
- };
- /**
- * Will update the password column along with the password scope variable
- */
- $scope.updatePassword = function (password) {
- var query = 'UPDATE auth SET password=? WHERE id=1';
- var passwordInput = $scope.dataTypeToTextConverter(password);
- $cordovaSQLite.execute(db, query, [passwordInput]).then(function (res) {
- $scope.viewAuth();
- $scope.setAuthVariables();
- },function (err) {
- console.log('updatePassword err', err);
- })
- };
- /**
- * Will update the Authorization column along with Authorization assests
- */
- $scope.updateAuthorization = function (Authorization) {
- var query = 'UPDATE auth SET Authorization=? WHERE id=1';
- var authorizationInput = $scope.dataTypeToTextConverter(Authorization);
- $cordovaSQLite.execute(db, query, [authorizationInput]).then(function (res) {
- $scope.viewAuth();
- $scope.setAuthVariables();
- },function (err) {
- console.log('updateAuthorization err', err);
- })
- };
- /**
- * Mainly for debugging, will console log out the current state of the touch params table
- */
- $scope.viewTouchParams = function () {
- var query = 'SELECT id, touchID, showTouchIDOption, touchLogin, showTouchLink FROM touch_params';
- $cordovaSQLite.execute(db, query).then(function (res) {
- console.log('touch_params Table: ', res);
- }, function (err) {
- console.log('touch_params Table Error: ', err)
- })
- };
- /**
- * Mainly for debugging, will console log out the current state of the auth table
- */
- $scope.viewAuth = function () {
- var query = 'SELECT id, username, password, Authorization FROM auth';
- $cordovaSQLite.execute(db, query).then(function (res) {
- console.log('Auth Table: ', res);
- }, function (err) {
- console.log('Auth Table Error: ', err);
- })
- };
- /**
- * Simply converts text data types
- * into more usable data types
- * @param variable
- * @returns {*}
- */
- $scope.textToDataTypeConverter = function (variable) {
- switch (variable) {
- case 'null':
- return null;
- break;
- case 'true':
- return true;
- break;
- case 'false':
- return false;
- break;
- default:
- return variable;
- }
- };
- /**
- * Simply converts data types into
- * text to be inserted into the sqlLite DB
- * @param variable
- * @returns {*}
- */
- $scope.dataTypeToTextConverter = function (variable) {
- switch (variable) {
- case true:
- return 'true';
- break;
- case false:
- return 'false';
- break;
- case null:
- return 'null';
- break;
- default:
- return variable;
- }
- };
- /**
- * End of Persistent SqlLite data functions
- */
Add Comment
Please, Sign In to add comment