diff --git a/app/app.module.js b/app/app.module.js deleted file mode 100644 index e69de29..0000000 diff --git a/app/controllers/index.js b/app/controllers/index.js new file mode 100644 index 0000000..c53e9f1 --- /dev/null +++ b/app/controllers/index.js @@ -0,0 +1,3 @@ +'use strict'; + +require('./main.controller'); diff --git a/app/controllers/main.controller.js b/app/controllers/main.controller.js index 51d7fd9..20e523d 100644 --- a/app/controllers/main.controller.js +++ b/app/controllers/main.controller.js @@ -1,26 +1,34 @@ -var wikistats = angular.module('wikistats', []); - -wikistats.controller('MainController', function($scope) { +module.exports = function($scope, pageViews) { $scope.groups = [ { 'name' : 'Dogs', 'breeds': [ 'Labrador', 'Retriever', 'Boxer', 'Cocker Spaniel' ]}, { 'name': 'Cats', 'breeds': [ 'Russian blue', 'Ragdoll', 'Norwegian Forest Cat' ]}, { 'name': 'Fish', 'breeds': [ 'Salmon', 'Pike', 'Trout', 'Bass' ]} ]; -}); + pageViews.get({ + project: "en.wikipedia", + article: "Dog", + from: "20160101", + to: "20160110", + }).$promise.then(function (result) { + angular.forEach(result.items, function(val, key) { + console.log({date: val.timestamp, views: val.views}); + }); + }); +} diff --git a/app/index.html b/app/index.html index e941468..882b1d2 100644 --- a/app/index.html +++ b/app/index.html @@ -1,41 +1,42 @@ Wikistats +

    {{animal.name}}

  • {{breed}}

diff --git a/app/index.js b/app/index.js new file mode 100644 index 0000000..7766ff5 --- /dev/null +++ b/app/index.js @@ -0,0 +1,15 @@ +'use struct'; + +require('angular'); +require('angular-resource'); + +var pageViews = require('./services/pageviews.service'); +var wikiservices = angular.module('wikiservices', ['ngResource']); +wikiservices.factory('pageViews', ['$resource', pageViews]); + +var MainController = require('./controllers/main.controller'); +var wikistats = angular.module('wikistats', ['wikiservices']); + +wikistats.controller('MainController', ['$scope','pageViews', MainController]); + + diff --git a/app/services/index.js b/app/services/index.js new file mode 100644 index 0000000..f2b87b4 --- /dev/null +++ b/app/services/index.js @@ -0,0 +1,3 @@ +'use strict'; + +require('./pageview.service'); diff --git a/app/services/pageviews.service.js b/app/services/pageviews.service.js new file mode 100644 index 0000000..7d4dd9e --- /dev/null +++ b/app/services/pageviews.service.js @@ -0,0 +1,6 @@ +module.exports = function($resource) { + var URL = 'https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/:project/all-access/user/:article/daily/:from/:to'; + return $resource(URL, {}, { + query: {method: 'GET'} + }); +} diff --git a/bower.json b/bower.json deleted file mode 100755 index 043d50a..0000000 --- a/bower.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "wikistats", - "authors": [ - "Emil Gedda " - ], - "description": "A page view stats tool for wikimedia", - "main": "", - "moduleType": [ - "node" - ], - "keywords": [ - "stats", - "pageviews", - "tool", - "wikimedia" - ], - "license": "BSD3", - "homepage": "https://tools.wmflabs.org/wikistats/", - "private": true, - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "dependencies": { - "angular": "^1.5.3", - "bootstrap": "^3.3.6", - "highcharts": "^4.2.3" - } -} diff --git a/gulpfile.js b/gulpfile.js index 4d9d58d..e9ef080 100755 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,79 +1,66 @@ -var gulp = require('gulp'), - sass = require('gulp-sass'), +var gulp = require('gulp'), + sass = require('gulp-sass'), browserSync = require('browser-sync').create(), - uglify = require('gulp-uglify'), - concat = require('gulp-concat'), - ngAnnotate = require('gulp-ng-annotate'), - sourcemaps = require('gulp-sourcemaps'), - minifyCSS = require('gulp-clean-css'), - jshint = require('gulp-jshint'); + uglify = require('gulp-uglify'), + sourcemaps = require('gulp-sourcemaps'), + minifyCSS = require('gulp-clean-css'), + jshint = require('gulp-jshint'), + source = require('vinyl-source-stream'), + streamify = require('gulp-streamify'), + browserify = require('browserify'), + concat = require('gulp-concat'), + buffer = require('vinyl-buffer'); -gulp.task('default', ['copy','copyvendor', 'css', 'js', 'lint']); +gulp.task('default', ['copy','copyvendor', 'css', 'js', 'lint']); gulp.task('browserSync', function() { browserSync.init({ server: { baseDir: 'dist' }, }) }) gulp.task('copy', function() { return gulp.src('app/*.html') .pipe(gulp.dest('dist')) - .pipe(browserSync.reload({ - stream: true - })) -}); + .pipe(browserSync.stream()); +}) gulp.task('copyvendor', function() { - return gulp.src(['bower_components/angular/angular.min.js', - 'bower_components/angular/angular.min.js.map', - 'bower_components/bootstrap/dist/css/bootstrap.min*']) + return gulp.src(['node_modules/angular/**/*', 'node_modules/angular-resource/**/', + 'node_modules/bootstrap/dist/css/**/']) .pipe(gulp.dest('dist/vendor')) - .pipe(browserSync.reload({ - stream: true - })) -}); - - +}) gulp.task('lint', function() { return gulp.src('app/**/*.js') .pipe(jshint()) .pipe(jshint.reporter('default')) - .pipe(jshint.reporter('fail')) + //.pipe(jshint.reporter('fail')) }); gulp.task('watch', ['browserSync', 'default'], function(){ gulp.watch('assets/scss/**/*.scss', ['css']); gulp.watch('app/**/*.js', ['lint', 'js']); gulp.watch('app/*.html', ['copy']); }) gulp.task('css', function() { return gulp.src('assets/scss/**/*.scss') .pipe(sass()) .pipe(concat('styles.min.css')) .pipe(minifyCSS()) .pipe(gulp.dest('dist/assets/css')) - .pipe(browserSync.reload({ - stream: true - })) + .pipe(browserSync.stream()); }) gulp.task('js', function () { - return gulp.src(['app/**/*.module.js', 'app/**/*.js']) - .pipe(sourcemaps.init()) - .pipe(concat('app.min.js')) - .pipe(ngAnnotate()) - .on('error', function () { - this.emit('end'); - }) - .pipe(uglify()) - .pipe(sourcemaps.write('maps')) + return browserify('./app/index.js').ignore('angular').bundle() + .pipe(source('app.min.js')) + .pipe(buffer()) + .pipe(sourcemaps.init({loadMaps: true})) + .pipe(streamify(uglify())) + .pipe(sourcemaps.write('.')) .pipe(gulp.dest('dist/assets/js')) - .pipe(browserSync.reload({ - stream: true - })) }) diff --git a/package.json b/package.json index 883a4be..62caa56 100644 --- a/package.json +++ b/package.json @@ -1,38 +1,45 @@ { "name": "wikistats", "version": "0.0.0", "description": "Page view statistics tool for wikimedia", "main": "gulpfile.js", "directories": { "doc": "doc", "test": "test" }, "dependencies": { + "angular": "^1.5.3", + "angular-resource": "^1.5.3", + "browserify": "^13.0.0", + "gulp-streamify": "^1.0.2", "karma": "^0.13.22", - "protractor": "^3.2.2" + "protractor": "^3.2.2", + "vinyl-buffer": "^1.0.0", + "vinyl-source-stream": "^1.1.0" }, "devDependencies": { + "bootstrap": "^3.3.6", "browser-sync": "^2.11.2", "gulp": "^3.9.1", "gulp-clean-css": "^2.0.4", "gulp-concat": "^2.6.0", "gulp-jshint": "^2.0.0", "gulp-ng-annotate": "^2.0.0", "gulp-sass": "^2.2.0", "gulp-sourcemaps": "^1.6.0", "gulp-uglify": "^1.5.3", "jshint": "^2.9.1" }, "scripts": { "test": "node node_modules/karma/bin/karma start test/karma.conf.js" }, "keywords": [ "wikimedia", "wikistats", "stats", "pageviews", "statistics" ], "author": "Emil Gedda and the Wikistats group", "license": "BSD-3-Clause" }