{"size": 1849, "ext": "js", "max_stars_repo_path": "client/states/page/page.js", "max_stars_repo_name": "foreveryh/loopback-angularjs", "max_stars_repo_stars_event_min_datetime": "2015-07-21T01:30:41.000Z", "max_stars_repo_stars_event_max_datetime": "2016-09-08T06:38:13.000Z", "max_issues_repo_path": "client/states/page/page.js", "max_issues_repo_name": "foreveryh/loopback-angularjs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/states/page/page.js", "max_forks_repo_name": "foreveryh/loopback-angularjs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 5, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.3389830508, "max_line_length": 99, "alphanum_fraction": 0.5056787453}
angular.module('Shu.page', ['ui.bootstrap', 'ui.utils', 'ui.router', 'ngAnimate', 'ngSanitize']);

angular.module('Shu.page')
  //Todo: 记录阅读数
  .config(function($stateProvider) {
    $stateProvider.state('article', {
      url: '/p/:id',
      templateUrl: 'states/page/article.html',
      data: {public: true},
      resolve: {
        article: function(Article, $stateParams) {
          return Article.findOne({
              filter: {
                where: {
                  id: $stateParams.id
                }
              }
            },
            function(success) {
              console.log(success)
            },
            function(error) {
              console.log(error)
            });
        }
      },
      controller: function($rootScope, $scope, $window, $sce, article, Pageview, Article) {
        $scope.$on('$stateChangeSuccess', function(evt, toState, toParams, fromState, fromParams) {
          $window.document.title = article.title + " - 简书";
          $rootScope.bodylayout = "post output reader-day-mode reader-font2";
        });
        //default page view
        article.pageview_count = 1;
        $scope.article = article;
        //fetch page view count
        Article.pageview({
            id: article.id
          },
          function(success) {
            article.pageview_count = success.count + 1;
            //update page view count
            Pageview.upsert({
              id: success.id,
              count: article.pageview_count
            });
          },
          function(error) {
            Pageview.upsert({
              articleId: article.id,
              count: article.pageview_count
            });
          });
        $scope.deliberatelyTrustDangerousHtml = function() {
          return $sce.trustAsHtml($scope.article.content);
        };
      }
    });
  });
