Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- angular.module('seekube.component.listingForum.controller', [])
- .controller('listingForumIndexCtrl', ['$scope', 'AlgoliaClient', function ($scope, AlgoliaClient) {
- $scope.forums = [];
- //translations
- $scope.monthTranslation = [];
- for (var i=1; i <= 12; ++i) {
- var trans = Translator.trans('month' + i, {}, 'seekube');
- $scope.monthTranslation[i] = trans.charAt(0).toUpperCase() + trans.slice(1);
- }
- console.log($scope.monthTranslation);
- $scope.filterModel = {
- string: "",
- pastForum: false,
- months: [],
- years: []
- };
- $scope.facets = {};
- $scope.queue = 1;
- var forumIdx = algoliasearchHelper(
- AlgoliaClient, 'dev_forum', {
- disjunctiveFacets: ['month', 'year'],
- hitsPerPage: 6
- }
- );
- $scope.isDisjunctiveRefined = forumIdx.isDisjunctiveRefined;
- forumIdx.addNumericRefinement('endAt', '>', moment().unix());
- var search = function() {
- $scope.queue++;
- $scope.forums = [];
- forumIdx.search();
- forumIdx.isRefined('month', '2');
- }
- //Search callback
- forumIdx.on('result', function (result) {
- $scope.$apply(function () {
- //Update the result set
- console.log(result);
- $scope.forums = result.hits;
- $scope.facets = {
- month: result.disjunctiveFacets[0].data,
- year: result.disjunctiveFacets[1].data
- };
- //Remove the loader if the queue is empty
- --$scope.queue;
- });
- });
- forumIdx.on('error', function (err) {
- $scope.$apply(function () {
- console.log(error);
- --$scope.queue;
- });
- })
- $scope.toggleRefine = function($event, facet, value) {
- $event.preventDefault();
- forumIdx.toggleRefine(facet, value);
- search();
- };
- //First result set
- forumIdx.search();
- //Add watchers
- $scope.$watch('filterModel.string', function (newValue, oldValue) {
- forumIdx.setQuery(newValue);
- search();
- });
- $scope.$watch('filterModel.pastForum', function(newValue, oldValue) {
- forumIdx.removeNumericRefinement('endAt', oldValue ? '<=' : '>', moment().unix());
- forumIdx.addNumericRefinement('endAt', newValue ? '<=' : '>', moment().unix());
- search();
- });
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement