0

So I am developing this app in which i want to apply pagination to list of templates.

template objects are stored in the list.

I am displaying thumbnails of templates on the page and I want to apply pagination for this page.

So far I have tried following solution but it didn't work.

It displaying the pagination correctly but when I click on the link its not updating the contents of the page.

list.html

<div class="container">
    <div class="homepage-header">
        <h2 class="homepage-title text-center wow fadeInDown animated" style="visibility: visible; animation-name: fadeInDown; -webkit-animation-name: fadeInDown;"> TEMPLATES </h2>
    </div>

    <div class="row">
        <div class="col-md-6 col-sm-6" style="text-align: left">
            <div class="form-inline">
                <div class="form-group has-feedback has-clear">
                    <input type="text" class="form-control" ng-model="searchParam" ng-model-options="{ debounce: 400 }" placeholder="Search template ..."
                    />
                    <a class="glyphicon glyphicon-remove-sign form-control-feedback form-control-clear" ng-click="searchParam = '';
                      retreivePageData(0);" ng-show="searchParam" style="pointer-events: auto; "></a>
                </div>
            </div>
        </div>
        <div class="col-md-6 col-sm-6" style="text-align: right; vertical-align: middle; padding-right: 30px;">
            <div class="form-inline">
                {{selectedOption}}

                    <i class="fa fa-toggle-on fa-2x active" ng-if="status == true" ng-click="changeStatus();" title="Show component based templates"></i>
                    <i class="fa fa-toggle-on fa-2x fa-rotate-180 inactive" ng-if="status == false" ng-click="changeStatus();" title="Show image based templates"></i>


                &nbsp;&nbsp;<button ng-click="newTemplateConfig()" class="btn btn-primary btn-xs" title="Add new template"><i class="fa fa-plus-circle fa-fw"></i>New Template</button>

            </div>
        </div>
    </div>

    <div class="homepage-ui-showcase-2-css row wow zoomIn animated" style="height: 402px;padding: 5px 0px; visibility: visible; animation-name: zoomIn; -webkit-animation-name: zoomIn;">
        <div ng-repeat="(templateIndex, templateModel) in templatesList | filter:searchParam | limitTo: itemsPerPage">
            <div class="active col-md-3 col-lg-3 col-sm-6 col-xs-12 mix design painting" style="display: inline-block;padding-top: 10px;"
            ng-init="visible=false" ng-mouseover="visible=true" ng-mouseleave="visible=false">
                <div class="portfolio-item shadow-effect-1 boxShadow" style="max-width: 250px;padding:0.3px;border:2px dotted  #bebede;cursor: pointer">
                    <div class="mainBadge">
                        <kbd>{{templateModel.badge}}</kbd>
                    </div>
                    <div ng-switch on="{{templateModel.type !== undefined && templateModel.type === 'Annotate'}}">
                        <div ng-switch-when="false" style="height: 130px;" ui-sref="/designer/:pageId({pageId:templateModel.id})" class="portfolio-img ">
                            <i style="opacity:0.4;padding-top:35px;padding-left:15px;margin-left: 30%;" class="fa fa-puzzle-piece fa-4x"></i>
                        </div>
                        <div ng-switch-when="true" style="height: 130px;" ui-sref="annotator/:annotatedTemplateId({annotatedTemplateId:templateModel.id})"
                        class="portfolio-img ">
                            <i style="opacity:0.4;padding-top:35px;padding-left:15px;margin-left: 30%;" class="fa fa-file-image-o fa-4x"></i>
                        </div>
                    </div>

                    <div class="portfolio-item-content" title="{{templateModel.name}}">
                        <h3 class="header" style="font-size: 13px;text-align: center;display:inline;">
                            {{templateModel.name}}
                        </h3>
                        <small class="pull-right" ng-show="visible" style="display: inline; padding-top: 4px">
                            <div ng-switch on="{{templateModel.type !== undefined && templateModel.type === 'Annotate'}}">
                                <div ng-switch-when="true" href="#" class="btn btn-xs btn-danger" title="Generate Communication"
                                 ui-sref="generateCommunication({mode:'A',id: templateModel.id})"
                                 ng-disabled="!templateModel.dynamic_entity"> <!--style="color:#9d9d9;"-->
                                    <i class="fa fa-file-pdf-o"></i>
                                </div>
                                <div ng-switch-when="false" href="#" class="btn btn-xs btn-danger" title="Generate Communication"
                                 ui-sref="generateCommunication({mode:'T',id: templateModel.id})"
                                 ng-disabled="!templateModel.dynamic_entity"> <!--style="color:#9d9d9;"-->
                                    <i class="fa fa-file-pdf-o"></i>
                                </div>
                            </div>
                        </small>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row " style="margin-top: 10px; padding-top:0px;">
        <div class="pagination-div pull-right" style="">            
            <!--<pagination class="pull-right" total-items="templatesList.length" ng-model="currentPage" max-size="maxSize" items-per-page="itemsPerPage"></pagination> -->            
            <uib-pagination total-items="templatesList.length" ng-model="currentPage" ng-change="pageChanged()" max-size="maxSize" class="pagination-sm" items-per-page="itemsPerPage" boundary-link-numbers="true"></uib-pagination>
        </div>
    </div>

</div>

list.controller.js

'use strict';

angular.module('rapid').controller('HomeListController',
    function($scope, $rootScope, $window, $modal, ServiceFactory, toaster, ReadFileService, AnnotationService, AnnotateService, DocumentService) {

        $scope.templatesList = [];
        $scope.selectedOption = 'All';
        $scope.annotateTemplateMeta = [];
        $scope.rapidTemplateMeta = [];
        $scope.maxSize = 5;

        $scope.init = function() {
            $scope.status = true;
            $scope.selectedOption = "Image Based";
            $scope.retrieveTemplates($scope.status);
            $scope.currentPage = 1;
        };

        $scope.changeStatus = function(){
            $scope.status = !$scope.status;
            $scope.retrieveTemplates($scope.status);
        };

        $scope.retrieveTemplates = function(selectedOption) {
            $scope.templatesList = [];

            if(selectedOption) {
                $scope.selectedOption = "Image Based";
                $scope.fetchAnnotationTemplates("Annotate");
            } else {
                $scope.selectedOption = "Component Based";
                $scope.fetchRapidTemplates("Rapid");
            }
        };

        $scope.fetchAnnotationTemplates = function(selectedOption) {
            AnnotateService.get().$promise.then(function(result) {
                $scope.annotateTemplateMeta = result[0];
                console.log('Annotated template count :: ' + result[0].length);
                if (selectedOption === 'All') {
                    $scope.fetchRapidTemplates(selectedOption);
                } else {
                    $scope.prepareTemplateList(selectedOption);
                }
            });
        };

        $scope.fetchRapidTemplates = function(selectedOption) {
            ServiceFactory.PagesService.getAllPages().$promise.then(function(result) {
                $scope.rapidTemplateMeta = result[0];
                console.log('Rapid template count :: ' + result[0].length);
                $scope.prepareTemplateList(selectedOption);
            });
        };

        $scope.prepareTemplateList = function(selectedOption) {
            $scope.itemsPerPage = 1;
            var getPaginatedTemplateList = 'getList';
            $scope.currentPage = 0;
            if (selectedOption === 'Annotate') {
                $scope.annotateTemplateMeta.forEach(function(annotate) {
                    var templateObject = {};
                    templateObject = { id: annotate.id, name: annotate.name, type: "Annotate", dynamic_entity:annotate.dynamic_entity, badge:"Image Based" };
                    $scope.templatesList.push(templateObject);
                });

            } else if (selectedOption === 'Rapid') {
                $scope.rapidTemplateMeta.forEach(function(rapidTemplate) {
                    var templateObject = {};
                    templateObject = { id: rapidTemplate._id, name: rapidTemplate.name, type: "Component", dynamic_entity:rapidTemplate.pageObj.entity, badge:"Component Based" };
                    $scope.templatesList.push(templateObject);
                });
                //alert('Rapid count '+selectedOption + $rootScope.rapidTemplateMeta.length);
            } else {
                $scope.annotateTemplateMeta.forEach(function(annotate) {
                    var templateObject = {};
                    templateObject = { id: annotate.id, name: annotate.name, type: "Annotate", dynamic_entity:annotate.dynamic_entity, badge:"Image Based"  };
                    $scope.templatesList.push(templateObject);
                });
                $scope.rapidTemplateMeta.forEach(function(rapidTemplate) {
                    var templateObject = {};
                    templateObject = { id: rapidTemplate._id, name: rapidTemplate.name, type: "Component", dynamic_entity:rapidTemplate.pageObj.entity, badge:"Component Based"  };
                    $scope.templatesList.push(templateObject);
                });

                $scope.totalItems = $scope.templatesList.length;
                $scope.maxSize = 5;
            }
            //$scope.retreivePageData(0);


        };

        $scope.setPage = function(pageNo) {
            $scope.currentPage = pageNo;
        };


        $scope.pageChanged = function() {
            alert('Page changed to: ' + $scope.currentPage);

            });
        };




        $scope.newTemplateConfig = function (size) {
                var modalInstance = $modal.open({
                    backdrop: 'static',
                    keyboard: false,
                    animation: $scope.animationsEnabled,
                    templateUrl: 'scripts/app/home/modal/template.modal.html',
                    controller: 'TemplateModalCtrl',
                    size: size,
                    resolve: {templateModel: function () {
                            return null;
                        },
                        title: function () {
                            return 'Create New Template';
                        },
                        templateType: function() {
                            if($scope.status) {
                                return 'Annotate';
                            } else {
                                return 'Rapid'
                            }
                        }
                    }
                });
                modalInstance.result.then(function (saveAnnotatedTemplateConfig) {
                    alert('modal result')
                    //$scope.saveAnnotatedTemplateConfig(saveAnnotatedTemplateConfig.templateConfigModel);
                }, function () {
                    console.log('Modal dismissed at: ' + new Date());
                });
            };


        $scope.init();

    });

Is there anything wrong with my code?

Please provide some inputs on this.

2
  • why not use ui-grid ? ui-grid.info Commented Mar 18, 2016 at 11:46
  • @VinoDang can you provide any inputs on how to use that? Commented Mar 18, 2016 at 11:57

1 Answer 1

1

You can use ui-grid directive to solve your pagination problem.

Please refer to the ui-grid API.

Checkout these 2 plunkers :

  1. Plunker 1

  2. Plunker 2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.