Skip to content

Commit

Permalink
fix #1 cache file list in localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
pm5 committed Mar 18, 2015
1 parent c398fc5 commit 60b50ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions app/app.ls
@@ -1,7 +1,7 @@
# Declare app level module which depends on filters, and services
PDFJS.workerSrc = '/pdf.worker.js'

angular.module "App" <[app.templates ngMaterial ui.router pdf angular-files-model filereader]>
angular.module "App" <[app.templates ngMaterial ui.router pdf angular-files-model filereader ngStorage]>

.config <[$stateProvider $urlRouterProvider $locationProvider]> ++ ($stateProvider, $urlRouterProvider, $locationProvider) ->
$stateProvider
Expand Down Expand Up @@ -65,10 +65,11 @@ angular.module "App" <[app.templates ngMaterial ui.router pdf angular-files-mode
), 100, 1
), per-page, $scope.pageCount-1

.controller LeftCtrl: <[$rootScope $scope $timeout $interval $mdSidenav $log FileReader]> ++ ($rootScope, $scope, $timeout, $interval, $mdSidenav, $log, FileReader) ->
.controller LeftCtrl: <[$rootScope $scope $timeout $interval $mdSidenav $log FileReader $localStorage]> ++ ($rootScope, $scope, $timeout, $interval, $mdSidenav, $log, FileReader, $localStorage) ->
# sample dropbox response:
# $scope.files = [{"bytes":2772798,"link":"https://dl.dropboxusercontent.com/1/view/2lv9585lhj8hnv0/ignite-od/au_Sandstorm-and-OpenDocument.pdf","name":"au_Sandstorm-and-OpenDocument.pdf","icon":"https://www.dropbox.com/static/images/icons64/page_white_acrobat.png"},{"bytes":2270164,"link":"https://dl.dropboxusercontent.com/1/view/nmoi7kfx3r2fynj/ignite-od/ianmakgill-what-happens-when-you-use-open-data-a-story-from-the-uk.pdf","name":"ianmakgill-what-happens-when-you-use-open-data-a-story-from-the-uk.pdf","icon":"https://www.dropbox.com/static/images/icons64/page_white_acrobat.png"}]
$scope.files = []
$scope.$storage = $localStorage
$scope.$storage.files ||= []
$scope.trigger = ->
console.log it
if 'File' is typeof! it
Expand All @@ -84,16 +85,16 @@ angular.module "App" <[app.templates ngMaterial ui.router pdf angular-files-mode
$scope.dropbox = -> Dropbox.choose do
success: (files) ->
console.log JSON.stringify files
$scope.$apply -> $scope.files = files
$scope.$apply -> $scope.$storage.files = files
link-type: 'direct'
multiselect: true
extensions: ['.pdf']

$scope.$watch 'localFiles' (files) -> if files?length
$scope.files = [file for file in files]
$scope.$storage.files = [file for file in files]

$scope.close = ->
$mdSidenav 'left' .close!
.then ->
$log.debug "close LEFT is done"
$rootScope.activeTab = 'about'
$rootScope.activeTab = 'about'
2 changes: 1 addition & 1 deletion app/partials/nav.jade
Expand Up @@ -12,5 +12,5 @@ md-sidenav.md-sidenav-left.md-whiteframe-z2(md-component-id='left', md-is-locked
input(type="file",multiple,accept="application/pdf",style="display: none")
| local files
ul(style="list-style: none")
li(ng-repeat="file in files")
li(ng-repeat="file in $storage.files")
md-button.md-warn(ng-click="trigger(file)") {{file.name}}
3 changes: 2 additions & 1 deletion bower.json
Expand Up @@ -18,7 +18,8 @@
"angular-ui-router": "0.2.11",
"angular-pdf": "git://github.com/clkao/angularjs-pdf#page-fit",
"angular-files-model": "^0.1.1",
"angular-filereader": "git://github.com/genu/angular-filereader#patch-1"
"angular-filereader": "git://github.com/genu/angular-filereader#patch-1",
"ngstorage": "~0.3.0"
},
"overrides": [
{
Expand Down
1 change: 1 addition & 0 deletions bower.json.ls
Expand Up @@ -17,6 +17,7 @@ dependencies:
"angular-pdf": 'git://github.com/clkao/angularjs-pdf#page-fit'
"angular-files-model": "^0.1.1"
"angular-filereader": 'git://github.com/genu/angular-filereader#patch-1'
"ngstorage": "~0.3.0"

overrides:
"angular":
Expand Down

0 comments on commit 60b50ee

Please sign in to comment.