Skip to content

Commit

Permalink
feature/character-detail-comic-list — Comics list screen relative to …
Browse files Browse the repository at this point in the history
…a character with infinite scroll. Pretty cool as space is reserved in the grid and there is no relayout.
  • Loading branch information
jeandat committed Mar 22, 2016
1 parent 781ac09 commit 892c354
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/_ionic.app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ in ionic's _variables.scss file.
// The path for our ionicons font files, relative to the built CSS in www/css
$ionicons-font-path: "fonts";
$base-background-color: #DDD;
$dark: #333;

// Override default font family
//$font-family-sans-serif: "Roboto", "Segoe UI", "Arial", sans-serif;
Expand Down
7 changes: 3 additions & 4 deletions app/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@

$stateProvider

// setup an abstract state for the apps directive
// setup an abstract state for the apps directive
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'common/layout/layout.jade'
})

// Each app has its own nav history stack:

.state('app.characterList', {
url: '/characters',
views: {
Expand All @@ -66,7 +64,8 @@
.state('app.characterDetailComicList', {
url: '/characters',
params: {
comics: []
comics: [],
character: {}
},
views: {
'app-characters': {
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions app/character/comics/_character-comics.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.character-comics{
&__cover-container{
padding: $content-padding/2;
}
&__cover-wrapper{
position: relative;
height: 0;
overflow: hidden;
// Clever technique to reserve space although we don't know the image size yet.
// We can do that because we know the image aspect ratio and padding values
// expressed in percentage are relative to the width.
// http://andmag.se/2012/10/responsive-images-how-to-prevent-reflow/
padding-bottom: 450/300 * 100%;
background-color: darken($base-background-color, 10%);
}
&__cover{
position: absolute;
top: 0;
left: 0;
width:100%;
}
}
26 changes: 25 additions & 1 deletion app/character/comics/character-comics.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
.module('app')
.controller('CharacterComicsController', CharacterComicsController);

function CharacterComicsController($log, $stateParams) {
function CharacterComicsController($log, $stateParams, comicService, $scope, throwErr) {

var vm = this;
vm.title = 'CharacterComicsController';
vm.comics = $stateParams.comics;
vm.character = $stateParams.character;
vm.hasMore = true;
vm.showMore = showMore;

activate();

Expand All @@ -19,6 +22,27 @@
$log.debug(vm.title + ' instantiated');
}

function showMore(){
$log.debug('Infinite scroll boundary reached');
comicService
.findByCharacterId(vm.character.id, {offset:vm.comics.length})
.then(updateList)
.catch(throwErr);

/////////////

function updateList(results){
var meta = _.get(results, 'meta');
$log.info('Loaded', (meta.count + meta.offset), '/', meta.total, 'comics');
// Update list of characters
vm.comics = _.concat(vm.comics, results);
// Update meta
vm.comics.meta = meta;
// Update boolean to know instantly if there is more
vm.hasMore = meta && (meta.count + meta.offset) < meta.total;
$scope.$broadcast('scroll.infiniteScrollComplete');
}
}
}

})();
Expand Down
11 changes: 10 additions & 1 deletion app/character/comics/character-comics.jade
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
ion-view.character-comics(view-title='Comics')
ion-content
ion-content(delegate-handle='characterComicsHandle')
.row.row-wrap
.col-33.character-comics__cover-container(ng-repeat='comic in vm.comics track by $index')
div.character-comics__cover-wrapper
img.character-comics__cover(ng-if='::comic.thumbnailUrlInPortraitUncanny' img-cache ic-src='{{::comic.thumbnailUrlInPortraitUncanny}}' width='100%' height='auto'
ui-sref='app.characterDetailComicDetail({comic:comic})')
img.character-comics__cover(ng-if='::!comic.thumbnailUrlInPortraitUncanny' width='100%' height='auto' ng-src='img/image-not-available_portrait-uncanny.png'
ui-sref='app.characterDetailComicDetail({comic:comic})')

ion-infinite-scroll(on-infinite='vm.showMore()' distance='20%' immediate-check='false' ng-if='vm.hasMore')
2 changes: 1 addition & 1 deletion app/character/list/character-list.jade
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ ion-view.characters(view-title='Characters')
i.icon.ion-android-favorite-outline(ng-click='vm.keep()')
| {{::character.name}}
.characters__footer
ion-spinner.spinner-assertive(ng-if='vm.searching')
ion-spinner(ng-if='vm.searching')
button.button.button-block.button-assertive.characters__show-more(ng-click='vm.loadMore()' ng-show='vm.hasMoreData')
| Show more
8 changes: 7 additions & 1 deletion app/comic/list/comic-list.run.js → app/comic/comic.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@
function addNewMethodsToComics(Restangular) {
Restangular.extendModel('comics', function (model) {
model.thumbnailUrl = getThumbnailUrl();
model.thumbnailUrlInPortraitUncanny = getThumbnailUrlInPortraitUncanny();
return model;

/////////////

function getThumbnailUrl() {
var tnl = model.thumbnail;
if(_.isEmpty(tnl) || _.endsWith(tnl.path, 'image_not_available')) return '';
if (_.isEmpty(tnl) || _.endsWith(tnl.path, 'image_not_available')) return '';
return tnl.path + '.' + tnl.extension;
}
function getThumbnailUrlInPortraitUncanny(){
var tnl = model.thumbnail;
if (_.isEmpty(tnl) || _.endsWith(tnl.path, 'image_not_available')) return '';
return tnl.path + '/portrait_uncanny.' + tnl.extension;
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/comic/list/comic-list.jade
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ ion-view.comics(view-title='Comics')
i.icon.ion-android-favorite-outline(ng-click='vm.keep()')
| {{::comic.title}}
.comics__footer
ion-spinner.spinner-assertive(ng-if='vm.searching')
ion-spinner(ng-if='vm.searching')
button.button.button-block.button-assertive.comics__show-more(ng-click='vm.loadMore()' ng-show='vm.hasMoreData')
| Show more
Binary file modified img/image-not-available.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/image-not-available_portrait-uncanny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/image-not-available_portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/image-not-available_portrait.pxm
Binary file not shown.

0 comments on commit 892c354

Please sign in to comment.