Skip to content

Commit

Permalink
indexed Db
Browse files Browse the repository at this point in the history
  • Loading branch information
prashishh committed May 24, 2013
1 parent 4668d06 commit 6dd946c
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 81 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ asp/calender-application/

js/app.js~HEAD

js/lib/index.html
js/lib/index.html
index copy.html
index2.html
11 changes: 7 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<script src="js/lib/date.js"></script>
<script src="js/lib/neptoeng.js"></script>
<script src="js/lib/engtonep.js"></script>
<script src="js/lib/indexedDB.js"></script>


</head>

Expand All @@ -33,16 +35,17 @@ <h1> नेपाली पात्रो! </h1>

<div class="left-navig" ng-click="decMonth();"></div>
<div class="right-navig" ng-click="incMonth();"></div>

<!-- calendar -->
<nep-calendar></nep-calendar>


</div>
<!-- end of ng-controller - Nepali Calendar -->

<a href="#popupBasic" data-rel="popup">Open Popup</a>



</body>
<div data-role="popup" id="popupBasic">
<p>This is a completely basic popup, no options set.<p>
</div>
<a href="index.html" data-role="button" data-icon="delete">Delete</a> </body>
</html>
113 changes: 112 additions & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,118 @@ var engMonth = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'Jul
// map nepali-english months for calendar
var nepengMonth = ['', 'Apr-May', 'May-June', 'June-July', 'July-Aug', 'Aug-Sept', 'Sept-Oct', 'Oct-Nov', 'Nov-Dec', 'Dec-Jan', 'Jan-Feb', 'Feb-Mar', 'Mar-Apr', ];


// text at top left of calendar - map to unicode
function changeTonep(month, year) {
return nepMonth[month] + ' ' + nepDigit[year[0]] + nepDigit[year[1]] + nepDigit[year[2]] + nepDigit[year[3]];
}
}

var database;

function initialSetup() {
console.log('in');

var request = indexedDB.open("nepali_calendar", 1);

request.onerror = function(event) {
console.log(event.target.errorCode);
};

request.onsuccess = function(event) {
database = request.result;
console.log('database opened successfully.');
};

request.onupgradeneeded = function(event) {
var db = event.target.result;
var objectStore = db.createObjectStore("calendar_events", { keyPath: "date"});
console.log('helo');
};

}

function findEvent() {
var request = indexedDB.open("nepali_calendar", 1);

request.onsuccess = function(event) {
database = event.target.result;
var transaction = database.transaction(["calendar_events"]);
var objectStore = transaction.objectStore("calendar_events");
var request = objectStore.get(2000101);
request.onsuccess = function(event) {
database.close();
console.log('found' + event.target.result.date + event.target.result.event);
};
request.onerror = function(e) {
console.log("Error Getting: ", e);
};
}

}

/*
// schema
var dbSchema = [{
name: 'calendar_events',
key: 'date',
indexes: [
{ name: 'date', field: 'date', unique: false }
]
}];
// init
var IDB = new DB({
name: 'db_calendar',
version: 1,
schema: dbSchema,
success: function (DBObject) {
db = DBObject;
// console.log(db);
// doStuff();
},
error: function (support, e) {
console.log('error initing db');
}
});
//test();
}
function doStuff () {
// make calls with the db object here
var data = [
{date: '20700103', event: 'PujaShe'}
];
db.insert({
store: 'calendar_events',
data: data,
replace: true,
success: function (rowsAdded, rowsFailed, e) {
// added
console.log('Added ' + rowsAdded.length + ' rows to animals');
},
error: function (rowsAdded, rowsFailed, e) {
// error
console.log(rowsFailed.length + ' rows failed insert');
}
});
}
/*
// get id = 5
db.get({
store: 'animals1',
id: 9,
success: function (data, e) {
console.log(data.name + ' is in the class ' + data['class']);
},
error: function (id, e) {
console.log('error getting row ' + id);
}
});
*/



34 changes: 0 additions & 34 deletions js/app.js~HEAD

This file was deleted.

34 changes: 0 additions & 34 deletions js/app.js~master

This file was deleted.

60 changes: 56 additions & 4 deletions js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
angular.module('Calendarapp.controllers',[])
.controller('nepaliCalendarCtrl', function($scope, $element) {

var cal_setup = localStorage.getItem('cal_setup');

if (cal_setup == null)
initialSetup();

else if ( cal_setup < 2 )
initialSetup();


// initial button status
$scope.navig_button = 0;
$scope.navig_change = 0;
Expand Down Expand Up @@ -34,8 +43,7 @@ angular.module('Calendarapp.controllers',[])
};

// set today's date
$scope.findTodayDate = function()
{
$scope.findTodayDate = function() {
if ($scope.navig_change == 0) {
var today = new Date();
$scope.selyear = today.getFullYear();
Expand All @@ -44,15 +52,59 @@ angular.module('Calendarapp.controllers',[])
}
}

$scope.setTodayDate = function()
{
$scope.setTodayDate = function() {
if ($scope.navig_change == 0) {
$scope.todaydate = $scope.convdate;
$scope.todaymonth = $scope.convmonth;
$scope.todayyear = $scope.convyear;
}
}

/*
$scope.getItemFromDb = function() {
// schema
var result;
var dbSchema = [{
name: 'calendar_events',
key: 'date',
indexes: [
{ name: 'date', field: 'date', unique: false }
]
}];
// init
var IDB = new DB({
name: 'db_calendar',
version: 1,
schema: dbSchema,
success: function (DBObject) {
db = DBObject;
db.get({
store: 'calendar_events',
id: 20700101,
success: function (data, e) {
// console.log(data.date)
result = data.date;
console.log(result);
},
error: function (id, e) {
console.log('error getting row ' + id);
}
});
return result;
},
error: function (support, e) {
console.log('error initing db');
}
});
console.log('asd');
return result;
}
/* for version 2
$scope.ADtoBS = function() {
$scope.ADtoBS_button = 1;
Expand Down
6 changes: 4 additions & 2 deletions js/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ angular.module('Calendarapp.directives', [])
replace: true,
link: function($scope, $element, $attrs)
{
findEvent();
// check if navig button is pressed
$scope.$watch('navig_button', function(newval, oldval) {

var temp = 1;
// get current date if no date is defined
if (typeof $scope.selyear === 'undefined' || typeof $scope.selmonth === 'undefined' || typeof $scope.selyear === 'undefined' )
$scope.findTodayDate();
Expand Down Expand Up @@ -151,7 +153,7 @@ angular.module('Calendarapp.directives', [])
'<div class="row">' +
'<span class="eng-font small-12 columns">' + neptoeng.DateConversion(day, $scope.convmonth, $scope.convyear).getDate() + '</span></div>' +
'<div class="row">' +
'<span class="small-12 columns" id="date-label">एकादशी</span></div>' +
'<span class="small-12 columns" id="date-label">'+ '1' +'</span></div>' +
'<div id="border-down"></div>' +
'</li>';
day++;
Expand All @@ -170,7 +172,7 @@ angular.module('Calendarapp.directives', [])
'<div class="row">' +
'<span class="eng-font small-12 columns">' + neptoeng.DateConversion(day, $scope.convmonth, $scope.convyear).getDate() + '</span></div>' +
'<div class="row">' +
'<span class="small-12 columns" id="date-label">एकादशी</span></div>' +
'<span class="small-12 columns" id="date-label">'+ '1'+'</span></div>' +
'<div id="border-down"></div>' +
'</li>';
day++;
Expand Down
9 changes: 9 additions & 0 deletions js/lib/indexedDB.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest.webapp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "http://prashishrajbhandari.com.np"
},
"icons": {
"16": "/img/icon16.png"
"128": "/img/icon128.png"
},
"default_locale": "en"
}

0 comments on commit 6dd946c

Please sign in to comment.