From dd51ca0033f57c41e74f8a00688d8aa743001861 Mon Sep 17 00:00:00 2001 From: Tomster Date: Tue, 5 Apr 2016 12:32:19 -0400 Subject: [PATCH 001/959] Initial Commit from Ember CLI v2.3.0-beta.1 _..., ,:^;,...; -+===;. ,,--++====++-,,, .: /....., :::::~+++++#:,+#++++++++++++++++++#*..: /,...... (,,,,,,::=+++##++++++++++++++++++++++#. :....../ ...,,,,,::++++++++++++++++++++++++++++++*..,...: *..+...,#@@@@@@@@@++++++++++++++++++++++#*....* @#,;##############@@@+*+#@@@@@@@@@@#*++#..< *@##@@+,-*^^^*-+@####@@@######@@@#####@@,,,+ @#@* @#@@@@#@@+--*^^*--#@@@@@@# @#@. @# @##+++@#, .@@#@@ #@# @@ +@@++++#@@ @@ :@@ :@#* @#@++++++@#* #@ @@+ :*+@@#;,.__.+@#@+,-^^.++@# @@++ ;* :*@@@##@@@@;++r._j^.+@##@+,.__,,@@++. /* ........+++++++++++++#@@@@@###@@#++++, ,: ...,@@@#++===----==@@@####,,....+++++ .: ......@@##@\ ; :@####@,,...... +++. ; .........@###, ; ;xx#@;,,..... *;+, | ........,*;xxxx--^--=xxx,........ :+#; ; ......,,;xxxxxxxxxxxxx;,..... *+# ; ......,::xxxx;. ...... +. . *; ......... +### .... / ,. /:| ,. .+: ... ;##++##, . ,#. (..v..;*./ ** ## ###* .:*&&&+. \.,....<, #&+**==-..,,__ ;## ### :,*+&&&&&&&v+#&,,.._/ #&&&&*...,::,,. ##; ,##* .*****;:&&&&&&&&& ,+*+;~*..*** *.* ### ###* ******* *+#&;* ##,;## **** :, ** ##### ## ### ###, ######## .##### ;## ## ####### ;## #### ,###. ########## ######## ### #### ### ### ### ########## #### #### ,## ### #######* ### ,### ##############: ## ### #### ,## :#### ### ##; ########## ########### ## .## ,### ####### ##### :###### ###### .###### #### ## ### ### ######* :##### #### ############# #### ################ ######## ### #####* *#* #: :### *###* *#### #* --- .bowerrc | 4 ++ .editorconfig | 34 ++++++++++++ .ember-cli | 9 ++++ .gitignore | 17 ++++++ .jshintrc | 32 ++++++++++++ .npmignore | 14 +++++ .travis.yml | 34 ++++++++++++ .watchmanconfig | 3 ++ LICENSE.md | 9 ++++ README.md | 26 ++++++++++ addon/.gitkeep | 0 app/.gitkeep | 0 bower.json | 15 ++++++ config/ember-try.js | 36 +++++++++++++ config/environment.js | 6 +++ ember-cli-build.js | 18 +++++++ index.js | 6 +++ package.json | 49 +++++++++++++++++ testem.json | 12 +++++ tests/.jshintrc | 52 +++++++++++++++++++ tests/dummy/app/app.js | 18 +++++++ tests/dummy/app/components/.gitkeep | 0 tests/dummy/app/controllers/.gitkeep | 0 tests/dummy/app/helpers/.gitkeep | 0 tests/dummy/app/index.html | 25 +++++++++ tests/dummy/app/models/.gitkeep | 0 tests/dummy/app/resolver.js | 3 ++ tests/dummy/app/router.js | 11 ++++ tests/dummy/app/routes/.gitkeep | 0 tests/dummy/app/styles/app.css | 0 tests/dummy/app/templates/application.hbs | 3 ++ tests/dummy/app/templates/components/.gitkeep | 0 tests/dummy/config/environment.js | 47 +++++++++++++++++ tests/dummy/public/crossdomain.xml | 15 ++++++ tests/dummy/public/robots.txt | 3 ++ tests/helpers/destroy-app.js | 5 ++ tests/helpers/module-for-acceptance.js | 23 ++++++++ tests/helpers/resolver.js | 11 ++++ tests/helpers/start-app.js | 18 +++++++ tests/index.html | 34 ++++++++++++ tests/integration/.gitkeep | 0 tests/test-helper.js | 6 +++ tests/unit/.gitkeep | 0 vendor/.gitkeep | 0 44 files changed, 598 insertions(+) create mode 100644 .bowerrc create mode 100644 .editorconfig create mode 100644 .ember-cli create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 .npmignore create mode 100644 .travis.yml create mode 100644 .watchmanconfig create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 addon/.gitkeep create mode 100644 app/.gitkeep create mode 100644 bower.json create mode 100644 config/ember-try.js create mode 100644 config/environment.js create mode 100644 ember-cli-build.js create mode 100644 index.js create mode 100644 package.json create mode 100644 testem.json create mode 100644 tests/.jshintrc create mode 100644 tests/dummy/app/app.js create mode 100644 tests/dummy/app/components/.gitkeep create mode 100644 tests/dummy/app/controllers/.gitkeep create mode 100644 tests/dummy/app/helpers/.gitkeep create mode 100644 tests/dummy/app/index.html create mode 100644 tests/dummy/app/models/.gitkeep create mode 100644 tests/dummy/app/resolver.js create mode 100644 tests/dummy/app/router.js create mode 100644 tests/dummy/app/routes/.gitkeep create mode 100644 tests/dummy/app/styles/app.css create mode 100644 tests/dummy/app/templates/application.hbs create mode 100644 tests/dummy/app/templates/components/.gitkeep create mode 100644 tests/dummy/config/environment.js create mode 100644 tests/dummy/public/crossdomain.xml create mode 100644 tests/dummy/public/robots.txt create mode 100644 tests/helpers/destroy-app.js create mode 100644 tests/helpers/module-for-acceptance.js create mode 100644 tests/helpers/resolver.js create mode 100644 tests/helpers/start-app.js create mode 100644 tests/index.html create mode 100644 tests/integration/.gitkeep create mode 100644 tests/test-helper.js create mode 100644 tests/unit/.gitkeep create mode 100644 vendor/.gitkeep diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 000000000..959e1696e --- /dev/null +++ b/.bowerrc @@ -0,0 +1,4 @@ +{ + "directory": "bower_components", + "analytics": false +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..47c543840 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,34 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +[*.js] +indent_style = space +indent_size = 2 + +[*.hbs] +insert_final_newline = false +indent_style = space +indent_size = 2 + +[*.css] +indent_style = space +indent_size = 2 + +[*.html] +indent_style = space +indent_size = 2 + +[*.{diff,md}] +trim_trailing_whitespace = false diff --git a/.ember-cli b/.ember-cli new file mode 100644 index 000000000..ee64cfed2 --- /dev/null +++ b/.ember-cli @@ -0,0 +1,9 @@ +{ + /** + Ember CLI sends analytics information by default. The data is completely + anonymous, but there are times when you might want to disable this behavior. + + Setting `disableAnalytics` to true will prevent any data from being sent. + */ + "disableAnalytics": false +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..86fceae7a --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist +/tmp + +# dependencies +/node_modules +/bower_components + +# misc +/.sass-cache +/connect.lock +/coverage/* +/libpeerconnection.log +npm-debug.log +testem.log diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 000000000..08096effa --- /dev/null +++ b/.jshintrc @@ -0,0 +1,32 @@ +{ + "predef": [ + "document", + "window", + "-Promise" + ], + "browser": true, + "boss": true, + "curly": true, + "debug": false, + "devel": true, + "eqeqeq": true, + "evil": true, + "forin": false, + "immed": false, + "laxbreak": false, + "newcap": true, + "noarg": true, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "regexp": false, + "undef": true, + "sub": true, + "strict": false, + "white": false, + "eqnull": true, + "esnext": true, + "unused": true +} diff --git a/.npmignore b/.npmignore new file mode 100644 index 000000000..49996f5a3 --- /dev/null +++ b/.npmignore @@ -0,0 +1,14 @@ +bower_components/ +tests/ +tmp/ +dist/ + +.bowerrc +.editorconfig +.ember-cli +.travis.yml +.npmignore +**/.gitkeep +bower.json +Brocfile.js +testem.json diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..8197d316c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,34 @@ +--- +language: node_js +node_js: + - "0.12" + +sudo: false + +cache: + directories: + - node_modules + +env: + - EMBER_TRY_SCENARIO=default + - EMBER_TRY_SCENARIO=ember-release + - EMBER_TRY_SCENARIO=ember-beta + - EMBER_TRY_SCENARIO=ember-canary + +matrix: + fast_finish: true + allow_failures: + - env: EMBER_TRY_SCENARIO=ember-canary + +before_install: + - export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH + - "npm config set spin false" + - "npm install -g npm@^2" + +install: + - npm install -g bower + - npm install + - bower install + +script: + - ember try $EMBER_TRY_SCENARIO test diff --git a/.watchmanconfig b/.watchmanconfig new file mode 100644 index 000000000..e7834e3e4 --- /dev/null +++ b/.watchmanconfig @@ -0,0 +1,3 @@ +{ + "ignore_dirs": ["tmp", "dist"] +} diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 000000000..02000b56e --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2016 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 000000000..311f5d763 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Ember-osf-models + +This README outlines the details of collaborating on this Ember addon. + +## Installation + +* `git clone` this repository +* `npm install` +* `bower install` + +## Running + +* `ember server` +* Visit your app at http://localhost:4200. + +## Running Tests + +* `npm test` (Runs `ember try:testall` to test your addon against multiple Ember versions) +* `ember test` +* `ember test --server` + +## Building + +* `ember build` + +For more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/). diff --git a/addon/.gitkeep b/addon/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/app/.gitkeep b/app/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/bower.json b/bower.json new file mode 100644 index 000000000..b4d76ddd1 --- /dev/null +++ b/bower.json @@ -0,0 +1,15 @@ +{ + "name": "ember-osf-models", + "dependencies": { + "ember": "2.3.0", + "ember-cli-shims": "0.1.0", + "ember-cli-test-loader": "0.2.2", + "ember-load-initializers": "0.1.7", + "ember-qunit-notifications": "0.1.0", + "jquery": "1.11.3", + "loader.js": "^3.5.0" + }, + "resolutions": { + "ember": "2.2.0" + } +} diff --git a/config/ember-try.js b/config/ember-try.js new file mode 100644 index 000000000..3e88bc612 --- /dev/null +++ b/config/ember-try.js @@ -0,0 +1,36 @@ +/*jshint node:true*/ +module.exports = { + scenarios: [ + { + name: 'default', + dependencies: { } + }, + { + name: 'ember-release', + dependencies: { + 'ember': 'components/ember#release' + }, + resolutions: { + 'ember': 'release' + } + }, + { + name: 'ember-beta', + dependencies: { + 'ember': 'components/ember#beta' + }, + resolutions: { + 'ember': 'beta' + } + }, + { + name: 'ember-canary', + dependencies: { + 'ember': 'components/ember#canary' + }, + resolutions: { + 'ember': 'canary' + } + } + ] +}; diff --git a/config/environment.js b/config/environment.js new file mode 100644 index 000000000..28a787b62 --- /dev/null +++ b/config/environment.js @@ -0,0 +1,6 @@ +/*jshint node:true*/ +'use strict'; + +module.exports = function(/* environment, appConfig */) { + return { }; +}; diff --git a/ember-cli-build.js b/ember-cli-build.js new file mode 100644 index 000000000..4ac391379 --- /dev/null +++ b/ember-cli-build.js @@ -0,0 +1,18 @@ +/*jshint node:true*/ +/* global require, module */ +var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); + +module.exports = function(defaults) { + var app = new EmberAddon(defaults, { + // Add options here + }); + + /* + This build file specifies the options for the dummy test app of this + addon, located in `/tests/dummy` + This build file does *not* influence how the addon or the app using it + behave. You most likely want to be modifying `./index.js` or app's build file + */ + + return app.toTree(); +}; diff --git a/index.js b/index.js new file mode 100644 index 000000000..bbb05c6d9 --- /dev/null +++ b/index.js @@ -0,0 +1,6 @@ +/* jshint node: true */ +'use strict'; + +module.exports = { + name: 'ember-osf-models' +}; diff --git a/package.json b/package.json new file mode 100644 index 000000000..477e995d3 --- /dev/null +++ b/package.json @@ -0,0 +1,49 @@ +{ + "name": "ember-osf-models", + "version": "0.0.0", + "description": "The default blueprint for ember-cli addons.", + "directories": { + "doc": "doc", + "test": "tests" + }, + "scripts": { + "build": "ember build", + "start": "ember server", + "test": "ember try:testall" + }, + "repository": "", + "engines": { + "node": ">= 0.10.0" + }, + "author": "", + "license": "MIT", + "devDependencies": { + "broccoli-asset-rev": "^2.2.0", + "ember-ajax": "0.7.1", + "ember-cli": "2.3.0-beta.1", + "ember-cli-app-version": "^1.0.0", + "ember-cli-dependency-checker": "^1.2.0", + "ember-cli-htmlbars": "^1.0.1", + "ember-cli-htmlbars-inline-precompile": "^0.3.1", + "ember-cli-inject-live-reload": "^1.3.1", + "ember-cli-qunit": "^1.2.1", + "ember-cli-release": "0.2.8", + "ember-cli-sri": "^2.0.0", + "ember-cli-uglify": "^1.2.0", + "ember-data": "^2.3.0", + "ember-disable-prototype-extensions": "^1.0.0", + "ember-disable-proxy-controllers": "^1.0.1", + "ember-export-application-global": "^1.0.4", + "ember-resolver": "^2.0.3", + "ember-try": "~0.0.8" + }, + "keywords": [ + "ember-addon" + ], + "dependencies": { + "ember-cli-babel": "^5.1.5" + }, + "ember-addon": { + "configPath": "tests/dummy/config" + } +} diff --git a/testem.json b/testem.json new file mode 100644 index 000000000..0f35392cf --- /dev/null +++ b/testem.json @@ -0,0 +1,12 @@ +{ + "framework": "qunit", + "test_page": "tests/index.html?hidepassed", + "disable_watching": true, + "launch_in_ci": [ + "PhantomJS" + ], + "launch_in_dev": [ + "PhantomJS", + "Chrome" + ] +} diff --git a/tests/.jshintrc b/tests/.jshintrc new file mode 100644 index 000000000..6ec0b7c15 --- /dev/null +++ b/tests/.jshintrc @@ -0,0 +1,52 @@ +{ + "predef": [ + "document", + "window", + "location", + "setTimeout", + "$", + "-Promise", + "define", + "console", + "visit", + "exists", + "fillIn", + "click", + "keyEvent", + "triggerEvent", + "find", + "findWithAssert", + "wait", + "DS", + "andThen", + "currentURL", + "currentPath", + "currentRouteName" + ], + "node": false, + "browser": false, + "boss": true, + "curly": true, + "debug": false, + "devel": false, + "eqeqeq": true, + "evil": true, + "forin": false, + "immed": false, + "laxbreak": false, + "newcap": true, + "noarg": true, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "regexp": false, + "undef": true, + "sub": true, + "strict": false, + "white": false, + "eqnull": true, + "esnext": true, + "unused": true +} diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js new file mode 100644 index 000000000..d8e5c713c --- /dev/null +++ b/tests/dummy/app/app.js @@ -0,0 +1,18 @@ +import Ember from 'ember'; +import Resolver from './resolver'; +import loadInitializers from 'ember/load-initializers'; +import config from './config/environment'; + +let App; + +Ember.MODEL_FACTORY_INJECTIONS = true; + +App = Ember.Application.extend({ + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix, + Resolver +}); + +loadInitializers(App, config.modulePrefix); + +export default App; diff --git a/tests/dummy/app/components/.gitkeep b/tests/dummy/app/components/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/dummy/app/controllers/.gitkeep b/tests/dummy/app/controllers/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/dummy/app/helpers/.gitkeep b/tests/dummy/app/helpers/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/dummy/app/index.html b/tests/dummy/app/index.html new file mode 100644 index 000000000..c9b432708 --- /dev/null +++ b/tests/dummy/app/index.html @@ -0,0 +1,25 @@ + + + + + + Dummy + + + + {{content-for "head"}} + + + + + {{content-for "head-footer"}} + + + {{content-for "body"}} + + + + + {{content-for "body-footer"}} + + diff --git a/tests/dummy/app/models/.gitkeep b/tests/dummy/app/models/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/dummy/app/resolver.js b/tests/dummy/app/resolver.js new file mode 100644 index 000000000..2fb563d6c --- /dev/null +++ b/tests/dummy/app/resolver.js @@ -0,0 +1,3 @@ +import Resolver from 'ember-resolver'; + +export default Resolver; diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js new file mode 100644 index 000000000..3bba78ebc --- /dev/null +++ b/tests/dummy/app/router.js @@ -0,0 +1,11 @@ +import Ember from 'ember'; +import config from './config/environment'; + +const Router = Ember.Router.extend({ + location: config.locationType +}); + +Router.map(function() { +}); + +export default Router; diff --git a/tests/dummy/app/routes/.gitkeep b/tests/dummy/app/routes/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.css new file mode 100644 index 000000000..e69de29bb diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs new file mode 100644 index 000000000..f8bc38e7b --- /dev/null +++ b/tests/dummy/app/templates/application.hbs @@ -0,0 +1,3 @@ +

Welcome to Ember

+ +{{outlet}} diff --git a/tests/dummy/app/templates/components/.gitkeep b/tests/dummy/app/templates/components/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js new file mode 100644 index 000000000..c59bcd538 --- /dev/null +++ b/tests/dummy/config/environment.js @@ -0,0 +1,47 @@ +/* jshint node: true */ + +module.exports = function(environment) { + var ENV = { + modulePrefix: 'dummy', + environment: environment, + baseURL: '/', + locationType: 'auto', + EmberENV: { + FEATURES: { + // Here you can enable experimental features on an ember canary build + // e.g. 'with-controller': true + } + }, + + APP: { + // Here you can pass flags/options to your application instance + // when it is created + } + }; + + if (environment === 'development') { + // ENV.APP.LOG_RESOLVER = true; + // ENV.APP.LOG_ACTIVE_GENERATION = true; + // ENV.APP.LOG_TRANSITIONS = true; + // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; + // ENV.APP.LOG_VIEW_LOOKUPS = true; + } + + if (environment === 'test') { + // Testem prefers this... + ENV.baseURL = '/'; + ENV.locationType = 'none'; + + // keep test console output quieter + ENV.APP.LOG_ACTIVE_GENERATION = false; + ENV.APP.LOG_VIEW_LOOKUPS = false; + + ENV.APP.rootElement = '#ember-testing'; + } + + if (environment === 'production') { + + } + + return ENV; +}; diff --git a/tests/dummy/public/crossdomain.xml b/tests/dummy/public/crossdomain.xml new file mode 100644 index 000000000..0c16a7a07 --- /dev/null +++ b/tests/dummy/public/crossdomain.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/tests/dummy/public/robots.txt b/tests/dummy/public/robots.txt new file mode 100644 index 000000000..f5916452e --- /dev/null +++ b/tests/dummy/public/robots.txt @@ -0,0 +1,3 @@ +# http://www.robotstxt.org +User-agent: * +Disallow: diff --git a/tests/helpers/destroy-app.js b/tests/helpers/destroy-app.js new file mode 100644 index 000000000..c3d4d1abb --- /dev/null +++ b/tests/helpers/destroy-app.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default function destroyApp(application) { + Ember.run(application, 'destroy'); +} diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js new file mode 100644 index 000000000..ed23003db --- /dev/null +++ b/tests/helpers/module-for-acceptance.js @@ -0,0 +1,23 @@ +import { module } from 'qunit'; +import startApp from '../helpers/start-app'; +import destroyApp from '../helpers/destroy-app'; + +export default function(name, options = {}) { + module(name, { + beforeEach() { + this.application = startApp(); + + if (options.beforeEach) { + options.beforeEach.apply(this, arguments); + } + }, + + afterEach() { + destroyApp(this.application); + + if (options.afterEach) { + options.afterEach.apply(this, arguments); + } + } + }); +} diff --git a/tests/helpers/resolver.js b/tests/helpers/resolver.js new file mode 100644 index 000000000..b208d38d0 --- /dev/null +++ b/tests/helpers/resolver.js @@ -0,0 +1,11 @@ +import Resolver from '../../resolver'; +import config from '../../config/environment'; + +const resolver = Resolver.create(); + +resolver.namespace = { + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix +}; + +export default resolver; diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js new file mode 100644 index 000000000..e098f1d5b --- /dev/null +++ b/tests/helpers/start-app.js @@ -0,0 +1,18 @@ +import Ember from 'ember'; +import Application from '../../app'; +import config from '../../config/environment'; + +export default function startApp(attrs) { + let application; + + let attributes = Ember.merge({}, config.APP); + attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; + + Ember.run(() => { + application = Application.create(attributes); + application.setupForTesting(); + application.injectTestHelpers(); + }); + + return application; +} diff --git a/tests/index.html b/tests/index.html new file mode 100644 index 000000000..64cb47e31 --- /dev/null +++ b/tests/index.html @@ -0,0 +1,34 @@ + + + + + + Dummy Tests + + + + {{content-for "head"}} + {{content-for "test-head"}} + + + + + + {{content-for "head-footer"}} + {{content-for "test-head-footer"}} + + + {{content-for "body"}} + {{content-for "test-body"}} + + + + + + + + + {{content-for "body-footer"}} + {{content-for "test-body-footer"}} + + diff --git a/tests/integration/.gitkeep b/tests/integration/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test-helper.js b/tests/test-helper.js new file mode 100644 index 000000000..e6cfb70fe --- /dev/null +++ b/tests/test-helper.js @@ -0,0 +1,6 @@ +import resolver from './helpers/resolver'; +import { + setResolver +} from 'ember-qunit'; + +setResolver(resolver); diff --git a/tests/unit/.gitkeep b/tests/unit/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/.gitkeep b/vendor/.gitkeep new file mode 100644 index 000000000..e69de29bb From 139bc6bfdd35816cfa8274c0e3f48ba21f5c8735 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 5 Apr 2016 12:37:51 -0400 Subject: [PATCH 002/959] Update package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 477e995d3..3c362dc6e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ember-osf-models", - "version": "0.0.0", - "description": "The default blueprint for ember-cli addons.", + "version": "0.0.1", + "description": "Ember Data models for the OSF APIv2", "directories": { "doc": "doc", "test": "tests" From 436e487bc6cf88e5a9412656693b336d5bcd815f Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 6 Apr 2016 13:43:54 -0400 Subject: [PATCH 003/959] First commit --- .editorconfig | 4 +-- addon/adapters/application.js | 18 ++++++++++ addon/authenticators/osf-token.js | 31 +++++++++++++++++ addon/authorizers/osf-token.js | 7 ++++ addon/models/node.js | 40 ++++++++++++++++++++++ addon/models/user.js | 9 +++++ addon/serializers/application.js | 23 +++++++++++++ app/adapters/application.js | 1 + app/authenticators/osf-token.js | 1 + app/authorizers/osf-token.js | 1 + app/models/node.js | 1 + app/models/user.js | 1 + app/serializers/application.js | 1 + package.json | 7 +++- tests/unit/adapters/application-test.js | 12 +++++++ tests/unit/models/node-test.js | 12 +++++++ tests/unit/models/user-test.js | 12 +++++++ tests/unit/serializers/application-test.js | 15 ++++++++ 18 files changed, 193 insertions(+), 3 deletions(-) create mode 100644 addon/adapters/application.js create mode 100644 addon/authenticators/osf-token.js create mode 100644 addon/authorizers/osf-token.js create mode 100644 addon/models/node.js create mode 100644 addon/models/user.js create mode 100644 addon/serializers/application.js create mode 100644 app/adapters/application.js create mode 100644 app/authenticators/osf-token.js create mode 100644 app/authorizers/osf-token.js create mode 100644 app/models/node.js create mode 100644 app/models/user.js create mode 100644 app/serializers/application.js create mode 100644 tests/unit/adapters/application-test.js create mode 100644 tests/unit/models/node-test.js create mode 100644 tests/unit/models/user-test.js create mode 100644 tests/unit/serializers/application-test.js diff --git a/.editorconfig b/.editorconfig index 47c543840..9a13d9b1e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,11 +11,11 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true indent_style = space -indent_size = 2 +indent_size = 4 [*.js] indent_style = space -indent_size = 2 +indent_size = 4 [*.hbs] insert_final_newline = false diff --git a/addon/adapters/application.js b/addon/adapters/application.js new file mode 100644 index 000000000..9f4b34755 --- /dev/null +++ b/addon/adapters/application.js @@ -0,0 +1,18 @@ +import Ember from 'ember'; +import DS from 'ember-data'; +import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; + +import config from 'ember-get-config'; + +export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { + authorizer: 'authorizer:osf-token', + + host: config.OSF.apiUrl, + pathForType: Ember.String.pluralize, + urlForFindRecord (id, modelName/*, snapshot*/) { + return `${this.get('host')}${Ember.String.pluralize(modelName)}/${id}/`; + }, + urlForFindAll (modelName) { + return `${this.get('host')}${Ember.String.pluralize(modelName)}/`; + } +}); diff --git a/addon/authenticators/osf-token.js b/addon/authenticators/osf-token.js new file mode 100644 index 000000000..af2e40909 --- /dev/null +++ b/addon/authenticators/osf-token.js @@ -0,0 +1,31 @@ +import Ember from 'ember'; +import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; + +import config from 'ember-get-config'; + +export default BaseAuthenticator.extend({ + store: Ember.inject.service(), + authUrl: `${config.OSF.authUrl}/`, + _test (accessToken) { + return Ember.$.ajax({ + method: 'GET', + url: `${config.OSF.apiUrl}users/me/`, + dataType: 'json', + contentType: 'application/json', + xhrFields: {withCredentials: true}, + headers: { + Authorization: `Bearer ${accessToken}` + } + }).then(function(res) { + res.data.attributes.accessToken = accessToken; + return res.data; + }); + }, + restore(data) { + let accessToken = data.attributes.accessToken; + return this._test(accessToken).fail(this.invalidate); + }, + authenticate(accessToken) { + return this._test(accessToken); + } +}); diff --git a/addon/authorizers/osf-token.js b/addon/authorizers/osf-token.js new file mode 100644 index 000000000..b418d884c --- /dev/null +++ b/addon/authorizers/osf-token.js @@ -0,0 +1,7 @@ +import Base from 'ember-simple-auth/authorizers/base'; + +export default Base.extend({ + authorize(sessionData, setHeader) { + setHeader('Authorization', `Bearer ${sessionData.attributes.accessToken}`); + } +}); diff --git a/addon/models/node.js b/addon/models/node.js new file mode 100644 index 000000000..303672694 --- /dev/null +++ b/addon/models/node.js @@ -0,0 +1,40 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + title: DS.attr('string'), + description: DS.attr('string'), + category: DS.attr('string'), + + currentUserPermissions: DS.attr(''), + + fork: DS.attr('boolean'), + collection: DS.attr('boolean'), + registration: DS.attr('boolean'), + public: DS.attr('boolean'), + + dateCreated: DS.attr('date'), + dateModified: DS.attr('date'), + + tags: DS.attr(), + + templateFrom: DS.attr('string'), + + // TODO? + // links = LinksField({'html': 'get_absolute_html_url'}) + + parent: DS.belongsTo('node', { + inverse: 'children' + }), + children: DS.hasMany('nodes', { + inverse: 'parent' + }), + //comments: DS.hasMany('comments'), + //contributors: DS.hasMany('node-contributors') + //files: DS.hasMany('files'), + //forkedFrom: DS.belongsTo('node'), + //nodeLinks: DS.hasMany('node-pointers'), + //registrations: DS.hasMany('registrations'), + //primaryInistution: DS.belongsTo('institution'), + root: DS.belongsTo('node') + //logs: DS.hasMany('node-logs'), +}); diff --git a/addon/models/user.js b/addon/models/user.js new file mode 100644 index 000000000..1dd745bce --- /dev/null +++ b/addon/models/user.js @@ -0,0 +1,9 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + given_name: DS.attr('string'), + middle_names: DS.attr(), + family_name: DS.attr('string'), + + nodes: DS.hasMany('nodes') +}); diff --git a/addon/serializers/application.js b/addon/serializers/application.js new file mode 100644 index 000000000..78f02e162 --- /dev/null +++ b/addon/serializers/application.js @@ -0,0 +1,23 @@ +import Ember from 'ember'; +import DS from 'ember-data'; + +export default DS.JSONAPISerializer.extend({ + _normalizeAttributes(attributes) { + var normalized = {}; + Object.keys(attributes).forEach(function(key) { + normalized[Ember.String.camelize(key)] = attributes[key]; + }); + return normalized; + }, + normalizeSingleResponse(_, __, payload) { + payload.data.attributes = this._normalizeAttributes(payload.data.attributes); + return this._super(...arguments); + }, + normalizeArrayResponse(_, __, payload) { + payload.data = payload.data.map((record) => { + record.attributes = this._normalizeAttributes(record.attributes); + return record; + }); + return this._super(...arguments); + } +}); diff --git a/app/adapters/application.js b/app/adapters/application.js new file mode 100644 index 000000000..4545c2704 --- /dev/null +++ b/app/adapters/application.js @@ -0,0 +1 @@ +export { default } from 'ember-osf-models/adapters/application'; diff --git a/app/authenticators/osf-token.js b/app/authenticators/osf-token.js new file mode 100644 index 000000000..6b5f2e347 --- /dev/null +++ b/app/authenticators/osf-token.js @@ -0,0 +1 @@ +export { default } from 'ember-osf-models/authenticators/osf-token'; diff --git a/app/authorizers/osf-token.js b/app/authorizers/osf-token.js new file mode 100644 index 000000000..fb06be6d5 --- /dev/null +++ b/app/authorizers/osf-token.js @@ -0,0 +1 @@ +export { default } from 'ember-osf-models/authorizers/osf-token'; diff --git a/app/models/node.js b/app/models/node.js new file mode 100644 index 000000000..58b58f09c --- /dev/null +++ b/app/models/node.js @@ -0,0 +1 @@ +export { default } from 'ember-osf-models/models/node'; diff --git a/app/models/user.js b/app/models/user.js new file mode 100644 index 000000000..a7014554e --- /dev/null +++ b/app/models/user.js @@ -0,0 +1 @@ +export { default } from 'ember-osf-models/models/user'; diff --git a/app/serializers/application.js b/app/serializers/application.js new file mode 100644 index 000000000..93394e443 --- /dev/null +++ b/app/serializers/application.js @@ -0,0 +1 @@ +export { default } from 'ember-osf-models/serializers/application'; diff --git a/package.json b/package.json index 3c362dc6e..078e31eff 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,16 @@ "ember-cli-sri": "^2.0.0", "ember-cli-uglify": "^1.2.0", "ember-data": "^2.3.0", + "ember-data-url-templates": "^0.1.0", "ember-disable-prototype-extensions": "^1.0.0", "ember-disable-proxy-controllers": "^1.0.1", "ember-export-application-global": "^1.0.4", "ember-resolver": "^2.0.3", - "ember-try": "~0.0.8" + "ember-simple-auth": "^1.0.1", + "ember-try": "~0.0.8", + "uri-templates": "^0.1.9", + "uuid": "^2.0.1", + "xdg-basedir": "^2.0.0" }, "keywords": [ "ember-addon" diff --git a/tests/unit/adapters/application-test.js b/tests/unit/adapters/application-test.js new file mode 100644 index 000000000..f0a2101e7 --- /dev/null +++ b/tests/unit/adapters/application-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:application', 'Unit | Adapter | application', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/models/node-test.js b/tests/unit/models/node-test.js new file mode 100644 index 000000000..6652dfbe1 --- /dev/null +++ b/tests/unit/models/node-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('node', 'Unit | Model | node', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/models/user-test.js b/tests/unit/models/user-test.js new file mode 100644 index 000000000..ba211109a --- /dev/null +++ b/tests/unit/models/user-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('user', 'Unit | Model | user', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/serializers/application-test.js b/tests/unit/serializers/application-test.js new file mode 100644 index 000000000..705e9eced --- /dev/null +++ b/tests/unit/serializers/application-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('application', 'Unit | Serializer | application', { + // Specify the other units that are required for this test. + needs: ['serializer:application'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); From ececfe22b112cb2b8087b509b33dcf6e708c7a2f Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 6 Apr 2016 14:38:27 -0400 Subject: [PATCH 004/959] Move ember-osf-test to dummy app of ember-osf-models --- .env-dist | 2 + .gitignore | 2 + package.json | 12 ++- tests/dummy/app/controllers/application.js | 3 + tests/dummy/app/controllers/login.js | 12 +++ tests/dummy/app/index.html | 2 +- tests/dummy/app/router.js | 2 + tests/dummy/app/routes/application.js | 12 +++ tests/dummy/app/routes/index.js | 5 ++ tests/dummy/app/routes/login.js | 27 ++++++ tests/dummy/app/routes/nodes.js | 11 +++ tests/dummy/app/templates/application.hbs | 2 +- tests/dummy/app/templates/index.hbs | 1 + tests/dummy/app/templates/login.hbs | 2 + tests/dummy/app/templates/nodes.hbs | 6 ++ tests/dummy/config/environment.js | 99 ++++++++++++++-------- 16 files changed, 156 insertions(+), 44 deletions(-) create mode 100644 .env-dist create mode 100644 tests/dummy/app/controllers/application.js create mode 100644 tests/dummy/app/controllers/login.js create mode 100644 tests/dummy/app/routes/application.js create mode 100644 tests/dummy/app/routes/index.js create mode 100644 tests/dummy/app/routes/login.js create mode 100644 tests/dummy/app/routes/nodes.js create mode 100644 tests/dummy/app/templates/index.hbs create mode 100644 tests/dummy/app/templates/login.hbs create mode 100644 tests/dummy/app/templates/nodes.hbs diff --git a/.env-dist b/.env-dist new file mode 100644 index 000000000..db8f7f6d2 --- /dev/null +++ b/.env-dist @@ -0,0 +1,2 @@ +OSF_CLIENT_ID= +OSF_SCOPE=osf.users.all_read diff --git a/.gitignore b/.gitignore index 86fceae7a..7faac2787 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ /libpeerconnection.log npm-debug.log testem.log + +.env diff --git a/package.json b/package.json index 078e31eff..a971077ec 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "license": "MIT", "devDependencies": { "broccoli-asset-rev": "^2.2.0", + "dotenv": "^2.0.0", "ember-ajax": "0.7.1", "ember-cli": "2.3.0-beta.1", "ember-cli-app-version": "^1.0.0", @@ -31,16 +32,13 @@ "ember-cli-sri": "^2.0.0", "ember-cli-uglify": "^1.2.0", "ember-data": "^2.3.0", - "ember-data-url-templates": "^0.1.0", "ember-disable-prototype-extensions": "^1.0.0", "ember-disable-proxy-controllers": "^1.0.1", "ember-export-application-global": "^1.0.4", - "ember-resolver": "^2.0.3", - "ember-simple-auth": "^1.0.1", - "ember-try": "~0.0.8", - "uri-templates": "^0.1.9", - "uuid": "^2.0.1", - "xdg-basedir": "^2.0.0" + "ember-get-config": "0.0.2", + "ember-moment": "^6.1.0", + "ember-resolver": "2.0.3", + "ember-simple-auth": "^1.0.1" }, "keywords": [ "ember-addon" diff --git a/tests/dummy/app/controllers/application.js b/tests/dummy/app/controllers/application.js new file mode 100644 index 000000000..7c3893d23 --- /dev/null +++ b/tests/dummy/app/controllers/application.js @@ -0,0 +1,3 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({}); diff --git a/tests/dummy/app/controllers/login.js b/tests/dummy/app/controllers/login.js new file mode 100644 index 000000000..f67336e06 --- /dev/null +++ b/tests/dummy/app/controllers/login.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; + +import config from 'ember-get-config'; + +export default Ember.Controller.extend({ + session: Ember.inject.service(), + actions: { + login() { + window.location = `${config.OSF.authUrl}oauth2/authorize?response_type=token&scope=${config.OSF.scope}&client_id=${config.OSF.clientId}&redirect_uri=${encodeURI(window.location)}`; + } + } +}); diff --git a/tests/dummy/app/index.html b/tests/dummy/app/index.html index c9b432708..6ea4b2d29 100644 --- a/tests/dummy/app/index.html +++ b/tests/dummy/app/index.html @@ -3,7 +3,7 @@ - Dummy + EmberOsfTest diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 3bba78ebc..b67ca9cc7 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -6,6 +6,8 @@ const Router = Ember.Router.extend({ }); Router.map(function() { + this.route('nodes'); + this.route('login'); }); export default Router; diff --git a/tests/dummy/app/routes/application.js b/tests/dummy/app/routes/application.js new file mode 100644 index 000000000..1eefa67c8 --- /dev/null +++ b/tests/dummy/app/routes/application.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + store: Ember.inject.service(), + session: Ember.inject.service(), + model() { + if(this.get('session.isAuthenticated')) { + return this.get('store').findRecord('user', 'me'); + } + return null; + } +}); diff --git a/tests/dummy/app/routes/index.js b/tests/dummy/app/routes/index.js new file mode 100644 index 000000000..30e4e301b --- /dev/null +++ b/tests/dummy/app/routes/index.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default Ember.Route.extend(AuthenticatedRouteMixin, { +}); diff --git a/tests/dummy/app/routes/login.js b/tests/dummy/app/routes/login.js new file mode 100644 index 000000000..a4e925109 --- /dev/null +++ b/tests/dummy/app/routes/login.js @@ -0,0 +1,27 @@ +import Ember from 'ember'; +import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin'; + +import config from 'ember-get-config'; + +export default Ember.Route.extend(UnauthenticatedRouteMixin, { + session: Ember.inject.service(), + beforeModel() { + var accessToken; + if (config.DEV) { + accessToken = config.OSF.accessToken; + } + else { + // Acquire an OSF access token, then exchange it for a Jam token + var hash = window.location.hash.substring(1).split('&').map(function(str) { + return this[str.split('=')[0]] = str.split('=')[1], this; + }.bind({}))[0]; + if (!hash || !hash.access_token) { + return null; + } + window.location.hash = ''; + accessToken = hash.access_token; + } + return this.get('session').authenticate('authenticator:osf-token', accessToken) + .then(() => this.transitionTo('index')); + } +}); diff --git a/tests/dummy/app/routes/nodes.js b/tests/dummy/app/routes/nodes.js new file mode 100644 index 000000000..427ddbb94 --- /dev/null +++ b/tests/dummy/app/routes/nodes.js @@ -0,0 +1,11 @@ +import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default Ember.Route.extend(AuthenticatedRouteMixin, { + store: Ember.inject.service(), + session: Ember.inject.service(), + model() { + const user = this.modelFor('application'); + return user.get('nodes'); + } +}); diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index f8bc38e7b..2cd62a9f8 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1,3 +1,3 @@ -

Welcome to Ember

+

Welcome to OSF Ember Example App

{{outlet}} diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/tests/dummy/app/templates/index.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/tests/dummy/app/templates/login.hbs b/tests/dummy/app/templates/login.hbs new file mode 100644 index 000000000..33f7480f5 --- /dev/null +++ b/tests/dummy/app/templates/login.hbs @@ -0,0 +1,2 @@ +

Login to begin

+ diff --git a/tests/dummy/app/templates/nodes.hbs b/tests/dummy/app/templates/nodes.hbs new file mode 100644 index 000000000..9b5128943 --- /dev/null +++ b/tests/dummy/app/templates/nodes.hbs @@ -0,0 +1,6 @@ +{{#each model as |node|}} +

{{node.title}}

+

{{node.category}}

+

{{moment-format node.dateCreated}}

+

{{moment-format node.dateModified}}

+{{/each}} diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index c59bcd538..d7f437156 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -1,47 +1,76 @@ /* jshint node: true */ +require('dotenv').config(); module.exports = function(environment) { - var ENV = { - modulePrefix: 'dummy', - environment: environment, - baseURL: '/', - locationType: 'auto', - EmberENV: { - FEATURES: { - // Here you can enable experimental features on an ember canary build - // e.g. 'with-controller': true - } - }, - - APP: { - // Here you can pass flags/options to your application instance - // when it is created + var ENV = { + modulePrefix: 'dummy', + environment: environment, + baseURL: '/', + locationType: 'auto', + EmberENV: { + FEATURES: { + // Here you can enable experimental features on an ember canary build + // e.g. 'with-controller': true + } + }, + + APP: { + // Here you can pass flags/options to your application instance + // when it is created + }, + OSF: { + clientId: process.env.OSF_CLIENT_ID, + scope: process.env.OSF_SCOPE + }, + 'ember-simple-auth': { + authenticationRoute: 'login', + routeAfterAuthentication: 'index', + authorizer: 'authorizer:custom' + } + }; + + if (environment === 'development') { + //ENV.APP.LOG_RESOLVER = true; + //ENV.APP.LOG_ACTIVE_GENERATION = true; + //ENV.APP.LOG_TRANSITIONS = true; + //ENV.APP.LOG_TRANSITIONS_INTERNAL = true; + //ENV.APP.LOG_VIEW_LOOKUPS = true; + + + ENV.OSF.url = 'http://localhost:5000/'; + ENV.OSF.apiUrl = 'http://localhost:8000/v2/'; + ENV.OSF.authUrl = 'http://localhost:8080/'; + + ENV.OSF.accessToken = process.env.OSF_ACCESS_TOKEN; + ENV.DEV = true; } - }; - if (environment === 'development') { - // ENV.APP.LOG_RESOLVER = true; - // ENV.APP.LOG_ACTIVE_GENERATION = true; - // ENV.APP.LOG_TRANSITIONS = true; - // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; - // ENV.APP.LOG_VIEW_LOOKUPS = true; - } + if (environment === 'test') { + // Testem prefers this... + ENV.baseURL = '/'; + ENV.locationType = 'none'; - if (environment === 'test') { - // Testem prefers this... - ENV.baseURL = '/'; - ENV.locationType = 'none'; + // keep test console output quieter + ENV.APP.LOG_ACTIVE_GENERATION = false; + ENV.APP.LOG_VIEW_LOOKUPS = false; - // keep test console output quieter - ENV.APP.LOG_ACTIVE_GENERATION = false; - ENV.APP.LOG_VIEW_LOOKUPS = false; + ENV.APP.rootElement = '#ember-testing'; + } + + if (environment === 'staging') { - ENV.APP.rootElement = '#ember-testing'; - } + ENV.APP.LOG_TRANSITIONS = true; + ENV.OSF.url = 'https://staging.osf.io/'; + ENV.OSF.apiUrl = 'https://staging-api.osf.io/v2/'; + ENV.OSF.authUrl = 'https://staging-accounts.osf.io/'; + } - if (environment === 'production') { + if (environment === 'production') { - } + ENV.OSF.url = 'https://osf.io/'; + ENV.OSF.apiUrl = 'https://api.osf.io/v2/'; + ENV.OSF.authUrl = 'https://accounts.osf.io/'; + } - return ENV; + return ENV; }; From 9af0cbc92e07750d45eea9edc87dae7427d81645 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 6 Apr 2016 14:48:26 -0400 Subject: [PATCH 005/959] Some cleanup of example app - add bootstrap - add link to Nodes page --- bower.json | 3 ++- ember-cli-build.js | 32 ++++++++++++++++------- package.json | 3 ++- tests/dummy/app/templates/application.hbs | 12 ++++++--- tests/dummy/app/templates/index.hbs | 2 +- tests/dummy/app/templates/nodes.hbs | 12 ++++++--- 6 files changed, 44 insertions(+), 20 deletions(-) diff --git a/bower.json b/bower.json index b4d76ddd1..726a17e5a 100644 --- a/bower.json +++ b/bower.json @@ -11,5 +11,6 @@ }, "resolutions": { "ember": "2.2.0" - } + }, + "devDependencies": {} } diff --git a/ember-cli-build.js b/ember-cli-build.js index 4ac391379..fce710214 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -3,16 +3,28 @@ var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { - var app = new EmberAddon(defaults, { - // Add options here - }); + var app = new EmberAddon(defaults, { + }); - /* - This build file specifies the options for the dummy test app of this - addon, located in `/tests/dummy` - This build file does *not* influence how the addon or the app using it - behave. You most likely want to be modifying `./index.js` or app's build file - */ - return app.toTree(); + app.import('bower_components/bootstrap/dist/css/bootstrap.min.css'); + app.import('bower_components/bootstrap/dist/css/bootstrap-theme.min.css'); + app.import('bower_components/bootstrap/dist/js/bootstrap.min.js'); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff', { + destDir: 'fonts' + }); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot', { + destDir: 'fonts' + }); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg', { + destDir: 'fonts' + }); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf', { + destDir: 'fonts' + }); + app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2', { + destDir: 'fonts' + }); + + return app.toTree(); }; diff --git a/package.json b/package.json index a971077ec..4f9b6c69b 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "ember-cli-htmlbars": "^1.0.1", "ember-cli-htmlbars-inline-precompile": "^0.3.1", "ember-cli-inject-live-reload": "^1.3.1", + "ember-cli-moment-shim": "1.1.0", "ember-cli-qunit": "^1.2.1", "ember-cli-release": "0.2.8", "ember-cli-sri": "^2.0.0", @@ -36,7 +37,7 @@ "ember-disable-proxy-controllers": "^1.0.1", "ember-export-application-global": "^1.0.4", "ember-get-config": "0.0.2", - "ember-moment": "^6.1.0", + "ember-moment": "6.1.0", "ember-resolver": "2.0.3", "ember-simple-auth": "^1.0.1" }, diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index 2cd62a9f8..979afbede 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1,3 +1,9 @@ -

Welcome to OSF Ember Example App

- -{{outlet}} +
+ {{link-to 'Home' 'index' class="btn btn-default"}} +

Welcome to OSF Ember Example App

+
+
+ {{outlet}} +
+
+
diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs index c24cd6895..40bbcc845 100644 --- a/tests/dummy/app/templates/index.hbs +++ b/tests/dummy/app/templates/index.hbs @@ -1 +1 @@ -{{outlet}} +{{link-to 'My Nodes' 'nodes' class="btn btn-default"}} diff --git a/tests/dummy/app/templates/nodes.hbs b/tests/dummy/app/templates/nodes.hbs index 9b5128943..1be25a4e5 100644 --- a/tests/dummy/app/templates/nodes.hbs +++ b/tests/dummy/app/templates/nodes.hbs @@ -1,6 +1,10 @@ +

My Nodes

{{#each model as |node|}} -

{{node.title}}

-

{{node.category}}

-

{{moment-format node.dateCreated}}

-

{{moment-format node.dateModified}}

+
+
+

{{node.title}}

+

{{node.category}}

+

{{moment-format node.dateCreated}}

+

{{moment-format node.dateModified}}

+
{{/each}} From 4ba31ae036cc002770ac23fa02a173941da91405 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 6 Apr 2016 15:01:14 -0400 Subject: [PATCH 006/959] Update the README - add OSF_ACCESS_TOKEN to .env-dist --- .env-dist | 2 ++ README.md | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.env-dist b/.env-dist index db8f7f6d2..39028dbc6 100644 --- a/.env-dist +++ b/.env-dist @@ -1,2 +1,4 @@ OSF_CLIENT_ID= OSF_SCOPE=osf.users.all_read + +OSF_ACCESS_TOKEN= diff --git a/README.md b/README.md index 311f5d763..0815bde87 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Ember-osf-models +p# Ember-osf -This README outlines the details of collaborating on this Ember addon. +This repo contains code for interacting with the OSF APIv2 inside of an Ember app. ## Installation @@ -8,11 +8,24 @@ This README outlines the details of collaborating on this Ember addon. * `npm install` * `bower install` +## Configuration + +For local development, you will need to be running the [OSF APIv2](https://github.com/CenterForOpenScience/osf.io#running-the-api-server). +To connect to the APIv2 while using [fakecas](https://github.com/CenterForOpenScience/osf.io#running-the-osf), you will need to generate a +personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes). Next: + +```bash +cp .env-dist .env +``` +and edit the new .env file to replace `` with the newly generated token. + ## Running * `ember server` * Visit your app at http://localhost:4200. +**Note:** This runs the dummy app contained in /tests/dummy + ## Running Tests * `npm test` (Runs `ember try:testall` to test your addon against multiple Ember versions) From b9d586415ed3721e8b5af087a0a7e8d47283a16e Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 6 Apr 2016 15:02:42 -0400 Subject: [PATCH 007/959] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0815bde87..d8e59ecdf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -p# Ember-osf +# Ember OSF This repo contains code for interacting with the OSF APIv2 inside of an Ember app. From 424283c986350d5b0722aa7a04a10e9a24027ed8 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 6 Apr 2016 15:03:09 -0400 Subject: [PATCH 008/959] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d8e59ecdf..b9ed19fd7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This repo contains code for interacting with the OSF APIv2 inside of an Ember ap For local development, you will need to be running the [OSF APIv2](https://github.com/CenterForOpenScience/osf.io#running-the-api-server). To connect to the APIv2 while using [fakecas](https://github.com/CenterForOpenScience/osf.io#running-the-osf), you will need to generate a -personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes). Next: +personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes)). Next: ```bash cp .env-dist .env From 52a7b8d5ab29f79994b184c43273a114fb846c7d Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 6 Apr 2016 15:46:10 -0400 Subject: [PATCH 009/959] Move auth logic into mixin classes - also ember-osf-models to ember-osf --- addon/mixins/osf-login-controller.js | 12 +++++++++ addon/mixins/osf-login-route.js | 27 +++++++++++++++++++ app/adapters/application.js | 2 +- app/authenticators/osf-token.js | 2 +- app/authorizers/osf-token.js | 2 +- app/mixins/osf-login-controller.js | 1 + app/mixins/osf-login-route.js | 1 + app/models/node.js | 2 +- app/models/user.js | 2 +- app/serializers/application.js | 2 +- bower.json | 2 +- index.js | 2 +- package.json | 2 +- tests/dummy/app/controllers/login.js | 11 ++------ tests/dummy/app/router.js | 7 ++--- tests/dummy/app/routes/index.js | 3 +-- tests/dummy/app/routes/login.js | 27 ++----------------- .../unit/mixins/osf-login-controller-test.js | 12 +++++++++ tests/unit/mixins/osf-login-route-test.js | 12 +++++++++ 19 files changed, 83 insertions(+), 48 deletions(-) create mode 100644 addon/mixins/osf-login-controller.js create mode 100644 addon/mixins/osf-login-route.js create mode 100644 app/mixins/osf-login-controller.js create mode 100644 app/mixins/osf-login-route.js create mode 100644 tests/unit/mixins/osf-login-controller-test.js create mode 100644 tests/unit/mixins/osf-login-route-test.js diff --git a/addon/mixins/osf-login-controller.js b/addon/mixins/osf-login-controller.js new file mode 100644 index 000000000..35aa1f4c8 --- /dev/null +++ b/addon/mixins/osf-login-controller.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; + +import config from 'ember-get-config'; + +export default Ember.Mixin.create({ + session: Ember.inject.service(), + actions: { + login() { + window.location = `${config.OSF.authUrl}oauth2/authorize?response_type=token&scope=${config.OSF.scope}&client_id=${config.OSF.clientId}&redirect_uri=${encodeURI(window.location)}`; + } + } +}); diff --git a/addon/mixins/osf-login-route.js b/addon/mixins/osf-login-route.js new file mode 100644 index 000000000..5b9dcf5a4 --- /dev/null +++ b/addon/mixins/osf-login-route.js @@ -0,0 +1,27 @@ +import Ember from 'ember'; +import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin'; + +import config from 'ember-get-config'; + +export default Ember.Mixin.create(UnauthenticatedRouteMixin, { + session: Ember.inject.service(), + beforeModel() { + var accessToken; + if (config.DEV) { + accessToken = config.OSF.accessToken; + } + else { + // Acquire an OSF access token, then exchange it for a Jam token + var hash = window.location.hash.substring(1).split('&').map(function(str) { + return this[str.split('=')[0]] = str.split('=')[1], this; + }.bind({}))[0]; + if (!hash || !hash.access_token) { + return null; + } + window.location.hash = ''; + accessToken = hash.access_token; + } + return this.get('session').authenticate('authenticator:osf-token', accessToken) + .then(() => this.transitionTo('index')); + } +}); diff --git a/app/adapters/application.js b/app/adapters/application.js index 4545c2704..394d6c1c5 100644 --- a/app/adapters/application.js +++ b/app/adapters/application.js @@ -1 +1 @@ -export { default } from 'ember-osf-models/adapters/application'; +export { default } from 'ember-osf/adapters/application'; diff --git a/app/authenticators/osf-token.js b/app/authenticators/osf-token.js index 6b5f2e347..278c2f156 100644 --- a/app/authenticators/osf-token.js +++ b/app/authenticators/osf-token.js @@ -1 +1 @@ -export { default } from 'ember-osf-models/authenticators/osf-token'; +export { default } from 'ember-osf/authenticators/osf-token'; diff --git a/app/authorizers/osf-token.js b/app/authorizers/osf-token.js index fb06be6d5..5529a71b7 100644 --- a/app/authorizers/osf-token.js +++ b/app/authorizers/osf-token.js @@ -1 +1 @@ -export { default } from 'ember-osf-models/authorizers/osf-token'; +export { default } from 'ember-osf/authorizers/osf-token'; diff --git a/app/mixins/osf-login-controller.js b/app/mixins/osf-login-controller.js new file mode 100644 index 000000000..92cf3f6b4 --- /dev/null +++ b/app/mixins/osf-login-controller.js @@ -0,0 +1 @@ +export {default} from 'ember-osf/mixins/osf-login-controller'; diff --git a/app/mixins/osf-login-route.js b/app/mixins/osf-login-route.js new file mode 100644 index 000000000..fc97a87ea --- /dev/null +++ b/app/mixins/osf-login-route.js @@ -0,0 +1 @@ +export {default} from 'ember-osf/mixins/osf-login-route'; diff --git a/app/models/node.js b/app/models/node.js index 58b58f09c..276ce28c9 100644 --- a/app/models/node.js +++ b/app/models/node.js @@ -1 +1 @@ -export { default } from 'ember-osf-models/models/node'; +export { default } from 'ember-osf/models/node'; diff --git a/app/models/user.js b/app/models/user.js index a7014554e..8c74ff0eb 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -1 +1 @@ -export { default } from 'ember-osf-models/models/user'; +export { default } from 'ember-osf/models/user'; diff --git a/app/serializers/application.js b/app/serializers/application.js index 93394e443..4c9ed2b4e 100644 --- a/app/serializers/application.js +++ b/app/serializers/application.js @@ -1 +1 @@ -export { default } from 'ember-osf-models/serializers/application'; +export { default } from 'ember-osf/serializers/application'; diff --git a/bower.json b/bower.json index 726a17e5a..0efa60368 100644 --- a/bower.json +++ b/bower.json @@ -1,5 +1,5 @@ { - "name": "ember-osf-models", + "name": "ember-osf", "dependencies": { "ember": "2.3.0", "ember-cli-shims": "0.1.0", diff --git a/index.js b/index.js index bbb05c6d9..bcd7d47b6 100644 --- a/index.js +++ b/index.js @@ -2,5 +2,5 @@ 'use strict'; module.exports = { - name: 'ember-osf-models' + name: 'ember-osf' }; diff --git a/package.json b/package.json index 4f9b6c69b..26f46a8f2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "ember-osf-models", + "name": "ember-osf", "version": "0.0.1", "description": "Ember Data models for the OSF APIv2", "directories": { diff --git a/tests/dummy/app/controllers/login.js b/tests/dummy/app/controllers/login.js index f67336e06..5b1f6bac5 100644 --- a/tests/dummy/app/controllers/login.js +++ b/tests/dummy/app/controllers/login.js @@ -1,12 +1,5 @@ import Ember from 'ember'; -import config from 'ember-get-config'; +import OsfLoginControllerMixin from 'ember-osf/mixins/osf-login-controller'; -export default Ember.Controller.extend({ - session: Ember.inject.service(), - actions: { - login() { - window.location = `${config.OSF.authUrl}oauth2/authorize?response_type=token&scope=${config.OSF.scope}&client_id=${config.OSF.clientId}&redirect_uri=${encodeURI(window.location)}`; - } - } -}); +export default Ember.Controller.extend(OsfLoginControllerMixin); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index b67ca9cc7..41e09a078 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -2,12 +2,13 @@ import Ember from 'ember'; import config from './config/environment'; const Router = Ember.Router.extend({ - location: config.locationType + location: config.locationType }); Router.map(function() { - this.route('nodes'); - this.route('login'); + this.route('index', {path: '/'}); + this.route('nodes'); + this.route('login'); }); export default Router; diff --git a/tests/dummy/app/routes/index.js b/tests/dummy/app/routes/index.js index 30e4e301b..88747043e 100644 --- a/tests/dummy/app/routes/index.js +++ b/tests/dummy/app/routes/index.js @@ -1,5 +1,4 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Ember.Route.extend(AuthenticatedRouteMixin, { -}); +export default Ember.Route.extend(AuthenticatedRouteMixin, {}); diff --git a/tests/dummy/app/routes/login.js b/tests/dummy/app/routes/login.js index a4e925109..8dd12d294 100644 --- a/tests/dummy/app/routes/login.js +++ b/tests/dummy/app/routes/login.js @@ -1,27 +1,4 @@ import Ember from 'ember'; -import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin'; +import OsfLoginRouteMixin from 'ember-osf/mixins/osf-login-route'; -import config from 'ember-get-config'; - -export default Ember.Route.extend(UnauthenticatedRouteMixin, { - session: Ember.inject.service(), - beforeModel() { - var accessToken; - if (config.DEV) { - accessToken = config.OSF.accessToken; - } - else { - // Acquire an OSF access token, then exchange it for a Jam token - var hash = window.location.hash.substring(1).split('&').map(function(str) { - return this[str.split('=')[0]] = str.split('=')[1], this; - }.bind({}))[0]; - if (!hash || !hash.access_token) { - return null; - } - window.location.hash = ''; - accessToken = hash.access_token; - } - return this.get('session').authenticate('authenticator:osf-token', accessToken) - .then(() => this.transitionTo('index')); - } -}); +export default Ember.Route.extend(OsfLoginRouteMixin); diff --git a/tests/unit/mixins/osf-login-controller-test.js b/tests/unit/mixins/osf-login-controller-test.js new file mode 100644 index 000000000..2661b3397 --- /dev/null +++ b/tests/unit/mixins/osf-login-controller-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import OsfLoginControllerMixin from '../../../mixins/osf-login-controller'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | osf login controller'); + +// Replace this with your real tests. +test('it works', function(assert) { + let OsfLoginControllerObject = Ember.Object.extend(OsfLoginControllerMixin); + let subject = OsfLoginControllerObject.create(); + assert.ok(subject); +}); diff --git a/tests/unit/mixins/osf-login-route-test.js b/tests/unit/mixins/osf-login-route-test.js new file mode 100644 index 000000000..44df88811 --- /dev/null +++ b/tests/unit/mixins/osf-login-route-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import OsfLoginRouteMixin from '../../../mixins/osf-login-route'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | osf login route'); + +// Replace this with your real tests. +test('it works', function(assert) { + let OsfLoginRouteObject = Ember.Object.extend(OsfLoginRouteMixin); + let subject = OsfLoginRouteObject.create(); + assert.ok(subject); +}); From 31dc011441a40fb7c86a825f221525eb218c8353 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 15 Apr 2016 16:13:09 -0400 Subject: [PATCH 010/959] Support multiple .envs for different envs --- .gitignore | 4 ++++ tests/dummy/config/environment.js | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7faac2787..0cab8edcb 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,7 @@ npm-debug.log testem.log .env +.env-local +.env-stage* +.env-prod + diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index d7f437156..6c6d69ec4 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -1,7 +1,23 @@ /* jshint node: true */ -require('dotenv').config(); +var dotenv = require('dotenv'); +var path = require('path'); module.exports = function(environment) { + dotenv.config(); + dotenv.config({ + path: path.join( + __dirname, + '.env-' + { + development: 'local', + test: 'test', + staging: 'stage', + staging2: 'stage2', + production: 'prod' + }[environment] + ), + silent: true + }); + var ENV = { modulePrefix: 'dummy', environment: environment, @@ -64,6 +80,13 @@ module.exports = function(environment) { ENV.OSF.apiUrl = 'https://staging-api.osf.io/v2/'; ENV.OSF.authUrl = 'https://staging-accounts.osf.io/'; } + if (environment === 'staging2') { + + ENV.APP.LOG_TRANSITIONS = true; + ENV.OSF.url = 'https://staging2.osf.io/'; + ENV.OSF.apiUrl = 'https://staging2-api.osf.io/v2/'; + ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/'; + } if (environment === 'production') { From 718e90a0f008bfa570b6bb25a49139e9aa903fea Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 26 Apr 2016 13:07:25 -0400 Subject: [PATCH 011/959] Update login flow - do OAuth handshake rather than using personal access token - use correct CAS url - update README --- README.md | 13 +++++++++++-- addon/authenticators/osf-token.js | 2 +- addon/mixins/osf-login-controller.js | 2 +- addon/mixins/osf-login-route.js | 26 +++++++++----------------- bower.json | 3 ++- tests/dummy/config/environment.js | 27 +++++++++++---------------- 6 files changed, 35 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index b9ed19fd7..f0c14dda9 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,22 @@ This repo contains code for interacting with the OSF APIv2 inside of an Ember ap For local development, you will need to be running the [OSF APIv2](https://github.com/CenterForOpenScience/osf.io#running-the-api-server). To connect to the APIv2 while using [fakecas](https://github.com/CenterForOpenScience/osf.io#running-the-osf), you will need to generate a -personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes)). Next: +personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes)). +Next, depending on the environment you want to target, you will need to create the .env file. For: +- local: .env-local +- staging: .env-stage +- staging2: .env-stage2 +- production: .env-prod + +Do do this: ```bash -cp .env-dist .env +cp .env-dist .env- ``` and edit the new .env file to replace `` with the newly generated token. +For development, we reccomend point your local app to our staging servers: `ember s --environment staging` + ## Running * `ember server` diff --git a/addon/authenticators/osf-token.js b/addon/authenticators/osf-token.js index af2e40909..470c8730d 100644 --- a/addon/authenticators/osf-token.js +++ b/addon/authenticators/osf-token.js @@ -12,7 +12,7 @@ export default BaseAuthenticator.extend({ url: `${config.OSF.apiUrl}users/me/`, dataType: 'json', contentType: 'application/json', - xhrFields: {withCredentials: true}, + xhrFields: {withCredentials: false}, headers: { Authorization: `Bearer ${accessToken}` } diff --git a/addon/mixins/osf-login-controller.js b/addon/mixins/osf-login-controller.js index 35aa1f4c8..8d5545aea 100644 --- a/addon/mixins/osf-login-controller.js +++ b/addon/mixins/osf-login-controller.js @@ -6,7 +6,7 @@ export default Ember.Mixin.create({ session: Ember.inject.service(), actions: { login() { - window.location = `${config.OSF.authUrl}oauth2/authorize?response_type=token&scope=${config.OSF.scope}&client_id=${config.OSF.clientId}&redirect_uri=${encodeURI(window.location)}`; + window.location = `${config.OSF.authUrl}?response_type=token&scope=${config.OSF.scope}&client_id=${config.OSF.clientId}&redirect_uri=${encodeURI(window.location)}`; } } }); diff --git a/addon/mixins/osf-login-route.js b/addon/mixins/osf-login-route.js index 5b9dcf5a4..897250dd1 100644 --- a/addon/mixins/osf-login-route.js +++ b/addon/mixins/osf-login-route.js @@ -1,27 +1,19 @@ import Ember from 'ember'; import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin'; -import config from 'ember-get-config'; - export default Ember.Mixin.create(UnauthenticatedRouteMixin, { session: Ember.inject.service(), beforeModel() { - var accessToken; - if (config.DEV) { - accessToken = config.OSF.accessToken; - } - else { - // Acquire an OSF access token, then exchange it for a Jam token - var hash = window.location.hash.substring(1).split('&').map(function(str) { - return this[str.split('=')[0]] = str.split('=')[1], this; - }.bind({}))[0]; - if (!hash || !hash.access_token) { - return null; - } - window.location.hash = ''; - accessToken = hash.access_token; + // Acquire an OSF access token, then exchange it for a Jam token + var hash = window.location.hash.substring(1).split('&').map(function(str) { + return this[str.split('=')[0]] = str.split('=')[1], this; + }.bind({}))[0]; + if (!hash || !hash.access_token) { + return null; } - return this.get('session').authenticate('authenticator:osf-token', accessToken) + window.location.hash = ''; + var accessToken = hash.access_token; + return this.get('session').authenticate('authenticator:osf-token', accessToken) .then(() => this.transitionTo('index')); } }); diff --git a/bower.json b/bower.json index 0efa60368..36404c3ae 100644 --- a/bower.json +++ b/bower.json @@ -7,7 +7,8 @@ "ember-load-initializers": "0.1.7", "ember-qunit-notifications": "0.1.0", "jquery": "1.11.3", - "loader.js": "^3.5.0" + "loader.js": "^3.5.0", + "bootstrap": "^3.3.6" }, "resolutions": { "ember": "2.2.0" diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index 6c6d69ec4..da05e635c 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -3,19 +3,14 @@ var dotenv = require('dotenv'); var path = require('path'); module.exports = function(environment) { - dotenv.config(); dotenv.config({ - path: path.join( - __dirname, - '.env-' + { - development: 'local', - test: 'test', - staging: 'stage', - staging2: 'stage2', - production: 'prod' - }[environment] - ), - silent: true + path:'.env-' + { + development: 'local', + test: 'test', + staging: 'stage', + staging2: 'stage2', + production: 'prod' + }[environment] }); var ENV = { @@ -55,7 +50,7 @@ module.exports = function(environment) { ENV.OSF.url = 'http://localhost:5000/'; ENV.OSF.apiUrl = 'http://localhost:8000/v2/'; - ENV.OSF.authUrl = 'http://localhost:8080/'; + ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; ENV.OSF.accessToken = process.env.OSF_ACCESS_TOKEN; ENV.DEV = true; @@ -78,21 +73,21 @@ module.exports = function(environment) { ENV.APP.LOG_TRANSITIONS = true; ENV.OSF.url = 'https://staging.osf.io/'; ENV.OSF.apiUrl = 'https://staging-api.osf.io/v2/'; - ENV.OSF.authUrl = 'https://staging-accounts.osf.io/'; + ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; } if (environment === 'staging2') { ENV.APP.LOG_TRANSITIONS = true; ENV.OSF.url = 'https://staging2.osf.io/'; ENV.OSF.apiUrl = 'https://staging2-api.osf.io/v2/'; - ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/'; + ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; } if (environment === 'production') { ENV.OSF.url = 'https://osf.io/'; ENV.OSF.apiUrl = 'https://api.osf.io/v2/'; - ENV.OSF.authUrl = 'https://accounts.osf.io/'; + ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; } return ENV; From 3ec02b426e9aa6a1ba2fb9e98a00003b41f195dc Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 27 Apr 2016 12:35:21 -0400 Subject: [PATCH 012/959] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f0c14dda9..4531716a3 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Next, depending on the environment you want to target, you will need to create t - staging2: .env-stage2 - production: .env-prod -Do do this: +To do this: ```bash cp .env-dist .env- ``` From 2e63eb8f36b9632ed414fa569da5514d54f51319 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 27 Apr 2016 12:41:35 -0400 Subject: [PATCH 013/959] Update the README --- README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f0c14dda9..96fac16a9 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,17 @@ This repo contains code for interacting with the OSF APIv2 inside of an Ember ap ## Configuration +#### Running the OSF Locally (optional) + For local development, you will need to be running the [OSF APIv2](https://github.com/CenterForOpenScience/osf.io#running-the-api-server). To connect to the APIv2 while using [fakecas](https://github.com/CenterForOpenScience/osf.io#running-the-osf), you will need to generate a -personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes)). +personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes)). + +#### Using the Staging or Production API + +To do this, you will need to [create a developer application](https://staging.osf.io/settings/applications/) on the relevant version of the OSF. + +#### Create a .env Next, depending on the environment you want to target, you will need to create the .env file. For: - local: .env-local @@ -24,9 +32,12 @@ Do do this: ```bash cp .env-dist .env- ``` -and edit the new .env file to replace `` with the newly generated token. -For development, we reccomend point your local app to our staging servers: `ember s --environment staging` +Edit the new .env and replace: +- `` with the client id of your developer application +- `` with the newly generated token (if applicable) + +**Note**: For development, we reccomend point your local app to our staging servers: `ember s --environment staging` ## Running From 2bd91feb855bf1101ff88f4bceb02860c2e304e9 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 27 Apr 2016 12:42:33 -0400 Subject: [PATCH 014/959] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fd1b18ba5..a725ab653 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,16 @@ This repo contains code for interacting with the OSF APIv2 inside of an Ember ap ## Configuration +#### Using the Staging or Production API (preferred) + +To do this, you will need to [create a developer application](https://staging.osf.io/settings/applications/) on the relevant version of the OSF. + #### Running the OSF Locally (optional) For local development, you will need to be running the [OSF APIv2](https://github.com/CenterForOpenScience/osf.io#running-the-api-server). To connect to the APIv2 while using [fakecas](https://github.com/CenterForOpenScience/osf.io#running-the-osf), you will need to generate a personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes)). -#### Using the Staging or Production API - -To do this, you will need to [create a developer application](https://staging.osf.io/settings/applications/) on the relevant version of the OSF. - #### Create a .env Next, depending on the environment you want to target, you will need to create the .env file. For: From c90416027461fccffdb41ab3546b78cac82af26e Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 3 May 2016 13:13:40 -0400 Subject: [PATCH 015/959] Upgrade to ember2.4.3 --- .npmignore | 20 +++++----- .travis.yml | 1 + bower.json | 13 ++----- config/ember-try.js | 51 ++++++++++++++++++-------- package.json | 10 +++-- tests/dummy/app/app.js | 2 +- tests/helpers/module-for-acceptance.js | 4 +- 7 files changed, 60 insertions(+), 41 deletions(-) diff --git a/.npmignore b/.npmignore index 49996f5a3..fa8b147ae 100644 --- a/.npmignore +++ b/.npmignore @@ -1,14 +1,16 @@ -bower_components/ -tests/ -tmp/ -dist/ - +/bower_components +/config/ember-try.js +/dist +/tests +/tmp +**/.gitkeep .bowerrc .editorconfig .ember-cli +.gitignore +.jshintrc +.watchmanconfig .travis.yml -.npmignore -**/.gitkeep bower.json -Brocfile.js -testem.json +ember-cli-build.js +testem.js diff --git a/.travis.yml b/.travis.yml index 8197d316c..ee67302f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ cache: env: - EMBER_TRY_SCENARIO=default + - EMBER_TRY_SCENARIO=ember-1.13 - EMBER_TRY_SCENARIO=ember-release - EMBER_TRY_SCENARIO=ember-beta - EMBER_TRY_SCENARIO=ember-canary diff --git a/bower.json b/bower.json index 36404c3ae..35f7d58d2 100644 --- a/bower.json +++ b/bower.json @@ -1,17 +1,10 @@ { "name": "ember-osf", "dependencies": { - "ember": "2.3.0", - "ember-cli-shims": "0.1.0", + "ember": "~2.4.3", + "ember-cli-shims": "0.1.1", "ember-cli-test-loader": "0.2.2", - "ember-load-initializers": "0.1.7", "ember-qunit-notifications": "0.1.0", - "jquery": "1.11.3", - "loader.js": "^3.5.0", "bootstrap": "^3.3.6" - }, - "resolutions": { - "ember": "2.2.0" - }, - "devDependencies": {} + } } diff --git a/config/ember-try.js b/config/ember-try.js index 3e88bc612..014f603d6 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -3,33 +3,52 @@ module.exports = { scenarios: [ { name: 'default', - dependencies: { } + bower: { + dependencies: { } + } + }, + { + name: 'ember-1.13', + bower: { + dependencies: { + 'ember': '~1.13.0' + }, + resolutions: { + 'ember': '~1.13.0' + } + } }, { name: 'ember-release', - dependencies: { - 'ember': 'components/ember#release' - }, - resolutions: { - 'ember': 'release' + bower: { + dependencies: { + 'ember': 'components/ember#release' + }, + resolutions: { + 'ember': 'release' + } } }, { name: 'ember-beta', - dependencies: { - 'ember': 'components/ember#beta' - }, - resolutions: { - 'ember': 'beta' + bower: { + dependencies: { + 'ember': 'components/ember#beta' + }, + resolutions: { + 'ember': 'beta' + } } }, { name: 'ember-canary', - dependencies: { - 'ember': 'components/ember#canary' - }, - resolutions: { - 'ember': 'canary' + bower: { + dependencies: { + 'ember': 'components/ember#canary' + }, + resolutions: { + 'ember': 'canary' + } } } ] diff --git a/package.json b/package.json index 26f46a8f2..8bfd85f15 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "broccoli-asset-rev": "^2.2.0", "dotenv": "^2.0.0", "ember-ajax": "0.7.1", - "ember-cli": "2.3.0-beta.1", + "ember-cli": "^2.4.3", "ember-cli-app-version": "^1.0.0", "ember-cli-dependency-checker": "^1.2.0", "ember-cli-htmlbars": "^1.0.1", @@ -37,15 +37,19 @@ "ember-disable-proxy-controllers": "^1.0.1", "ember-export-application-global": "^1.0.4", "ember-get-config": "0.0.2", + "ember-load-initializers": "0.5.1", "ember-moment": "6.1.0", "ember-resolver": "2.0.3", - "ember-simple-auth": "^1.0.1" + "ember-simple-auth": "^1.0.1", + "loader": "2.1.0", + "loader.js": "4.0.3" }, "keywords": [ "ember-addon" ], "dependencies": { - "ember-cli-babel": "^5.1.5" + "ember-cli-babel": "^5.1.5", + "loader": "^2.1.0" }, "ember-addon": { "configPath": "tests/dummy/config" diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index d8e5c713c..831ad6106 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -1,6 +1,6 @@ import Ember from 'ember'; import Resolver from './resolver'; -import loadInitializers from 'ember/load-initializers'; +import loadInitializers from 'ember-load-initializers'; import config from './config/environment'; let App; diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js index ed23003db..8c8b74ecb 100644 --- a/tests/helpers/module-for-acceptance.js +++ b/tests/helpers/module-for-acceptance.js @@ -13,11 +13,11 @@ export default function(name, options = {}) { }, afterEach() { - destroyApp(this.application); - if (options.afterEach) { options.afterEach.apply(this, arguments); } + + destroyApp(this.application); } }); } From 2de30b1281452dc948963483ff3c2df67a3bbd81 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 3 May 2016 13:13:51 -0400 Subject: [PATCH 016/959] Change OAuth scopes to osf.full_read osf.full_write --- .env-dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env-dist b/.env-dist index 39028dbc6..1af1996f0 100644 --- a/.env-dist +++ b/.env-dist @@ -1,4 +1,4 @@ OSF_CLIENT_ID= -OSF_SCOPE=osf.users.all_read +OSF_SCOPE=osf.full_read osf.full_write OSF_ACCESS_TOKEN= From e90a702327053d612567c77211fef1f413e071ff Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 3 May 2016 13:29:09 -0400 Subject: [PATCH 017/959] Fix resource normalization for under_scored props closes #1 --- addon/serializers/application.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 78f02e162..15ee92a12 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -19,5 +19,8 @@ export default DS.JSONAPISerializer.extend({ return record; }); return this._super(...arguments); + }, + keyForAttribute(key) { + return Ember.String.camelize(key); } }); From f05ba3354b38dc02bd795ecb9fe599da34a8aad3 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 3 May 2016 15:21:53 -0400 Subject: [PATCH 018/959] Update README - usage docs - add Travis badges --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index a725ab653..0d2e3ffb7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,58 @@ # Ember OSF +`master` Build Status: [![Build Status](https://travis-ci.org/CenterForOpenScience/ember-osf.svg?branch=master)](https://travis-ci.org/CenterForOpenScience/ember-osf) + +`develop` Build Status: [![Build Status](https://travis-ci.org/CenterForOpenScience/ember-osf.svg?branch=develop)](https://travis-ci.org/CenterForOpenScience/ember-osf) + This repo contains code for interacting with the OSF APIv2 inside of an Ember app. +## Using this code in an Ember app + +1. Follow the instructions in **Installation** below +2. From the consuming Ember app: + a. `npm link ../ember-osf` + b. Edit the package.json to include: + ```json + ... + "devDependencies": { + ... + "ember-osf": "0.0.1", + ... + } + ... + ``` + c. Import code from ember-osf like: + ```javascript + import Ember from 'ember'; + import OsfLoginRouteMixin from 'ember-osf/mixins/osf-login-route'; + + export default Ember.Route.extend(OsfLoginRouteMixin); + ``` + +#### Ember Data: Using the OSF models + +The models, serializers, adapters bundled in this addon with be available to you automatically. +For example, simply do: +```javascript +this.store.findAll('node') +``` +to fetch all nodes. + +#### Ember Simple Auth config + +Specify that you want to use to osf-token authorizer in your app's enviornment.js like: +```javascript +... +var ENV = { + ... + 'ember-simple-auth': { + ... + authorizer: 'authorizer:osf-token' + } + ... +``` + + ## Installation * `git clone` this repository From a14571f210e5f180629a8d0ef6269fea9e729553 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 3 May 2016 15:39:29 -0400 Subject: [PATCH 019/959] Less ember-try scenarios; use ember 2.4.3 --- .travis.yml | 8 ++------ config/ember-try.js | 50 ++++----------------------------------------- 2 files changed, 6 insertions(+), 52 deletions(-) diff --git a/.travis.yml b/.travis.yml index ee67302f1..7b921748b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ --- language: node_js node_js: - - "0.12" + - "4.3.2" sudo: false @@ -10,11 +10,7 @@ cache: - node_modules env: - - EMBER_TRY_SCENARIO=default - - EMBER_TRY_SCENARIO=ember-1.13 - - EMBER_TRY_SCENARIO=ember-release - - EMBER_TRY_SCENARIO=ember-beta - - EMBER_TRY_SCENARIO=ember-canary + - EMBER_TRY_SCENARIO=lts matrix: fast_finish: true diff --git a/config/ember-try.js b/config/ember-try.js index 014f603d6..e60e88f14 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -2,53 +2,11 @@ module.exports = { scenarios: [ { - name: 'default', + name: 'lts', bower: { - dependencies: { } - } - }, - { - name: 'ember-1.13', - bower: { - dependencies: { - 'ember': '~1.13.0' - }, - resolutions: { - 'ember': '~1.13.0' - } - } - }, - { - name: 'ember-release', - bower: { - dependencies: { - 'ember': 'components/ember#release' - }, - resolutions: { - 'ember': 'release' - } - } - }, - { - name: 'ember-beta', - bower: { - dependencies: { - 'ember': 'components/ember#beta' - }, - resolutions: { - 'ember': 'beta' - } - } - }, - { - name: 'ember-canary', - bower: { - dependencies: { - 'ember': 'components/ember#canary' - }, - resolutions: { - 'ember': 'canary' - } + dependencies: { + ember: '2.4.3' + } } } ] From 24ac683389e2b860030114163512233395cec445 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 4 May 2016 09:16:20 -0400 Subject: [PATCH 020/959] A litte models overhaul - add BaseModel - better ApplicationSerializer - add Comment, CommentReport, and Contributor models --- addon/adapters/node.js | 8 +++++++ addon/models/base.js | 6 +++++ addon/models/comment-report.js | 6 +++++ addon/models/comment.js | 26 ++++++++++++++++++++++ addon/models/contributor.js | 9 ++++++++ addon/models/node.js | 12 +++++----- addon/models/user.js | 4 +++- addon/serializers/application.js | 20 ++++++++++++----- addon/transforms/embed.js | 11 +++++++++ addon/transforms/links.js | 13 +++++++++++ app/adapters/node.js | 1 + app/models/base.js | 1 + app/models/comment-report.js | 1 + app/models/comment.js | 1 + app/models/contributor.js | 1 + app/transforms/embed.js | 1 + app/transforms/links.js | 1 + tests/dummy/app/router.js | 4 +++- tests/dummy/app/routes/nodes/detail.js | 7 ++++++ tests/dummy/app/templates/nodes.hbs | 11 +-------- tests/dummy/app/templates/nodes/detail.hbs | 26 ++++++++++++++++++++++ tests/dummy/app/templates/nodes/index.hbs | 16 +++++++++++++ tests/dummy/config/environment.js | 2 +- tests/unit/adapters/node-test.js | 12 ++++++++++ tests/unit/models/base-test.js | 12 ++++++++++ tests/unit/models/comment-report-test.js | 12 ++++++++++ tests/unit/models/comment-test.js | 12 ++++++++++ tests/unit/models/contributor-test.js | 12 ++++++++++ tests/unit/transforms/embed-test.js | 12 ++++++++++ tests/unit/transforms/links-test.js | 12 ++++++++++ 30 files changed, 248 insertions(+), 24 deletions(-) create mode 100644 addon/adapters/node.js create mode 100644 addon/models/base.js create mode 100644 addon/models/comment-report.js create mode 100644 addon/models/comment.js create mode 100644 addon/models/contributor.js create mode 100644 addon/transforms/embed.js create mode 100644 addon/transforms/links.js create mode 100644 app/adapters/node.js create mode 100644 app/models/base.js create mode 100644 app/models/comment-report.js create mode 100644 app/models/comment.js create mode 100644 app/models/contributor.js create mode 100644 app/transforms/embed.js create mode 100644 app/transforms/links.js create mode 100644 tests/dummy/app/routes/nodes/detail.js create mode 100644 tests/dummy/app/templates/nodes/detail.hbs create mode 100644 tests/dummy/app/templates/nodes/index.hbs create mode 100644 tests/unit/adapters/node-test.js create mode 100644 tests/unit/models/base-test.js create mode 100644 tests/unit/models/comment-report-test.js create mode 100644 tests/unit/models/comment-test.js create mode 100644 tests/unit/models/contributor-test.js create mode 100644 tests/unit/transforms/embed-test.js create mode 100644 tests/unit/transforms/links-test.js diff --git a/addon/adapters/node.js b/addon/adapters/node.js new file mode 100644 index 000000000..6e925e874 --- /dev/null +++ b/addon/adapters/node.js @@ -0,0 +1,8 @@ +import ApplicationAdapter from './application'; + +export default ApplicationAdapter.extend({ + buildURL() { + // Embed contributors + return `${this._super(...arguments)}?embed=contributors`; + } +}); diff --git a/addon/models/base.js b/addon/models/base.js new file mode 100644 index 000000000..ab2133a26 --- /dev/null +++ b/addon/models/base.js @@ -0,0 +1,6 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + links: DS.attr('links'), + embeds: DS.attr('embed') +}); diff --git a/addon/models/comment-report.js b/addon/models/comment-report.js new file mode 100644 index 000000000..c3e00c482 --- /dev/null +++ b/addon/models/comment-report.js @@ -0,0 +1,6 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + category: DS.attr('string'), + text: DS.belongsTo('comment') +}); diff --git a/addon/models/comment.js b/addon/models/comment.js new file mode 100644 index 000000000..3e082627e --- /dev/null +++ b/addon/models/comment.js @@ -0,0 +1,26 @@ +import DS from 'ember-data'; + +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ + type: DS.attr('string'), + // TODO validation: maxLength + content: DS.attr('string'), + page: DS.attr('string'), + + // TODO dynamic belongsTo + //target TargetField(link_type='related', meta={'type': 'get_target_type'}) + user: DS.belongsTo('user'), + node: DS.belongsTo('node'), + replies: DS.hasMany('comment'), + + //reports: DS.hasMany('comment-report'), + + dateCreated: DS.attr('date'), + dateModified: DS.attr('date'), + modified: DS.attr('boolean'), + deleted: DS.attr('boolean'), + isAbuse: DS.attr('boolean'), + hasChildren: DS.attr('boolean'), + canEdit: DS.attr('boolean') +}); diff --git a/addon/models/contributor.js b/addon/models/contributor.js new file mode 100644 index 000000000..43a6fe84c --- /dev/null +++ b/addon/models/contributor.js @@ -0,0 +1,9 @@ +import DS from 'ember-data'; + +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ + bibliographic: DS.attr('boolean'), + permission: DS.attr('string'), + users: DS.hasMany('user') +}); diff --git a/addon/models/node.js b/addon/models/node.js index 303672694..069c2313b 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -1,6 +1,8 @@ import DS from 'ember-data'; -export default DS.Model.extend({ +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ title: DS.attr('string'), description: DS.attr('string'), category: DS.attr('string'), @@ -19,17 +21,15 @@ export default DS.Model.extend({ templateFrom: DS.attr('string'), - // TODO? - // links = LinksField({'html': 'get_absolute_html_url'}) - parent: DS.belongsTo('node', { inverse: 'children' }), children: DS.hasMany('nodes', { inverse: 'parent' }), - //comments: DS.hasMany('comments'), - //contributors: DS.hasMany('node-contributors') + comments: DS.hasMany('comments'), + contributors: DS.hasMany('contributors'), + //files: DS.hasMany('files'), //forkedFrom: DS.belongsTo('node'), //nodeLinks: DS.hasMany('node-pointers'), diff --git a/addon/models/user.js b/addon/models/user.js index 1dd745bce..0076a5c79 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -1,6 +1,8 @@ import DS from 'ember-data'; -export default DS.Model.extend({ +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ given_name: DS.attr('string'), middle_names: DS.attr(), family_name: DS.attr('string'), diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 15ee92a12..d8cdbd6ad 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -9,18 +9,28 @@ export default DS.JSONAPISerializer.extend({ }); return normalized; }, + _normalizeRecord(record) { + record.attributes = this._normalizeAttributes(record.attributes); + if (record.links) { + record.attributes.links = record.links; + } + return record; + }, normalizeSingleResponse(_, __, payload) { - payload.data.attributes = this._normalizeAttributes(payload.data.attributes); + payload.data = this._normalizeRecord(payload.data); return this._super(...arguments); }, normalizeArrayResponse(_, __, payload) { - payload.data = payload.data.map((record) => { - record.attributes = this._normalizeAttributes(record.attributes); - return record; - }); + payload.data = payload.data.map(this._normalizeRecord.bind(this)); return this._super(...arguments); }, keyForAttribute(key) { return Ember.String.camelize(key); + }, + + serializeIntoHash(/*hash, typeClass, snapshot, options*/) { + // Don't send links as part of hash + // TODO + return this._super(...arguments); } }); diff --git a/addon/transforms/embed.js b/addon/transforms/embed.js new file mode 100644 index 000000000..e366f928c --- /dev/null +++ b/addon/transforms/embed.js @@ -0,0 +1,11 @@ +import Transform from 'ember-data/transform'; + +export default Transform.extend({ + deserialize(serialized) { + return serialized; + }, + + serialize(deserialized) { + return deserialized; + } +}); diff --git a/addon/transforms/links.js b/addon/transforms/links.js new file mode 100644 index 000000000..3939be402 --- /dev/null +++ b/addon/transforms/links.js @@ -0,0 +1,13 @@ +/* + An empty stub. For now just leave links as a vanilla JS Object +*/ +import Transform from 'ember-data/transform'; + +export default Transform.extend({ + deserialize(serialized) { + return serialized; + }, + serialize(deserialized) { + return deserialized; + } +}); diff --git a/app/adapters/node.js b/app/adapters/node.js new file mode 100644 index 000000000..381a3ef8e --- /dev/null +++ b/app/adapters/node.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/node'; diff --git a/app/models/base.js b/app/models/base.js new file mode 100644 index 000000000..0a6182209 --- /dev/null +++ b/app/models/base.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/base'; diff --git a/app/models/comment-report.js b/app/models/comment-report.js new file mode 100644 index 000000000..26365a745 --- /dev/null +++ b/app/models/comment-report.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/comment-report'; diff --git a/app/models/comment.js b/app/models/comment.js new file mode 100644 index 000000000..1e2133172 --- /dev/null +++ b/app/models/comment.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/comment'; diff --git a/app/models/contributor.js b/app/models/contributor.js new file mode 100644 index 000000000..4830e131f --- /dev/null +++ b/app/models/contributor.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/contributor'; diff --git a/app/transforms/embed.js b/app/transforms/embed.js new file mode 100644 index 000000000..918fa17a7 --- /dev/null +++ b/app/transforms/embed.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/transforms/embed'; diff --git a/app/transforms/links.js b/app/transforms/links.js new file mode 100644 index 000000000..976a83d50 --- /dev/null +++ b/app/transforms/links.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/transforms/links'; diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 41e09a078..5a1c57bf8 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -7,7 +7,9 @@ const Router = Ember.Router.extend({ Router.map(function() { this.route('index', {path: '/'}); - this.route('nodes'); + this.route('nodes', function() { + this.route('detail', {path: '/:node_id'}); + }); this.route('login'); }); diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js new file mode 100644 index 000000000..b711cbe5f --- /dev/null +++ b/tests/dummy/app/routes/nodes/detail.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model(params) { + return this.store.findRecord('node', params.node_id); + } +}); diff --git a/tests/dummy/app/templates/nodes.hbs b/tests/dummy/app/templates/nodes.hbs index 1be25a4e5..c24cd6895 100644 --- a/tests/dummy/app/templates/nodes.hbs +++ b/tests/dummy/app/templates/nodes.hbs @@ -1,10 +1 @@ -

My Nodes

-{{#each model as |node|}} -
-
-

{{node.title}}

-

{{node.category}}

-

{{moment-format node.dateCreated}}

-

{{moment-format node.dateModified}}

-
-{{/each}} +{{outlet}} diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs new file mode 100644 index 000000000..914145e0f --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -0,0 +1,26 @@ +{{link-to 'Back to list' 'nodes' class="btn btn-default"}} +
+

{{model.title}}

+

{{model.category}}

+

{{moment-format model.dateCreated}}

+

{{moment-format model.dateModified}}

+

+ + View on OSF + +

+
+

+ +

+ + {{#each model.contributors as |contrib|}} + + {{contrib.bibliographic}} + + {{/each}} +
+

+

+
+ diff --git a/tests/dummy/app/templates/nodes/index.hbs b/tests/dummy/app/templates/nodes/index.hbs new file mode 100644 index 000000000..6058e0729 --- /dev/null +++ b/tests/dummy/app/templates/nodes/index.hbs @@ -0,0 +1,16 @@ +

My Nodes

+{{#each model as |node|}} +
+
+

{{node.title}}

+

{{node.category}}

+

{{moment-format node.dateCreated}}

+

{{moment-format node.dateModified}}

+

+ + View on OSF + + {{link-to 'Detail' 'nodes.detail' node.id class="btn btn-primary"}} +

+
+{{/each}} diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index da05e635c..cc96491a8 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -36,7 +36,7 @@ module.exports = function(environment) { 'ember-simple-auth': { authenticationRoute: 'login', routeAfterAuthentication: 'index', - authorizer: 'authorizer:custom' + authorizer: 'authorizer:osf-token' } }; diff --git a/tests/unit/adapters/node-test.js b/tests/unit/adapters/node-test.js new file mode 100644 index 000000000..2f8dd17ce --- /dev/null +++ b/tests/unit/adapters/node-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:node', 'Unit | Adapter | node', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/models/base-test.js b/tests/unit/models/base-test.js new file mode 100644 index 000000000..3065a6f45 --- /dev/null +++ b/tests/unit/models/base-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('base', 'Unit | Model | base', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/models/comment-report-test.js b/tests/unit/models/comment-report-test.js new file mode 100644 index 000000000..ffb169518 --- /dev/null +++ b/tests/unit/models/comment-report-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('comment-report', 'Unit | Model | comment report', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/models/comment-test.js b/tests/unit/models/comment-test.js new file mode 100644 index 000000000..62c8a2709 --- /dev/null +++ b/tests/unit/models/comment-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('comment', 'Unit | Model | comment', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/models/contributor-test.js b/tests/unit/models/contributor-test.js new file mode 100644 index 000000000..5caaffce3 --- /dev/null +++ b/tests/unit/models/contributor-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('contributor', 'Unit | Model | contributor', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/transforms/embed-test.js b/tests/unit/transforms/embed-test.js new file mode 100644 index 000000000..852d6ea23 --- /dev/null +++ b/tests/unit/transforms/embed-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('transform:embed', 'Unit | Transform | embed', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let transform = this.subject(); + assert.ok(transform); +}); diff --git a/tests/unit/transforms/links-test.js b/tests/unit/transforms/links-test.js new file mode 100644 index 000000000..106cb89ba --- /dev/null +++ b/tests/unit/transforms/links-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('transform:links', 'Unit | Transform | links', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let transform = this.subject(); + assert.ok(transform); +}); From 20f6b970bd3a722dd354114877e500730f977676 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 4 May 2016 16:12:17 -0400 Subject: [PATCH 021/959] Get unit tests passing --- .travis.yml | 10 +--------- config/ember-try.js | 13 ------------- package.json | 2 +- tests/unit/models/comment-report-test.js | 2 +- tests/unit/models/comment-test.js | 2 +- tests/unit/models/contributor-test.js | 2 +- tests/unit/models/node-test.js | 2 +- tests/unit/models/user-test.js | 2 +- tests/unit/serializers/application-test.js | 11 ++++------- 9 files changed, 11 insertions(+), 35 deletions(-) delete mode 100644 config/ember-try.js diff --git a/.travis.yml b/.travis.yml index 7b921748b..02533c978 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,14 +9,6 @@ cache: directories: - node_modules -env: - - EMBER_TRY_SCENARIO=lts - -matrix: - fast_finish: true - allow_failures: - - env: EMBER_TRY_SCENARIO=ember-canary - before_install: - export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH - "npm config set spin false" @@ -28,4 +20,4 @@ install: - bower install script: - - ember try $EMBER_TRY_SCENARIO test + - npm test diff --git a/config/ember-try.js b/config/ember-try.js deleted file mode 100644 index e60e88f14..000000000 --- a/config/ember-try.js +++ /dev/null @@ -1,13 +0,0 @@ -/*jshint node:true*/ -module.exports = { - scenarios: [ - { - name: 'lts', - bower: { - dependencies: { - ember: '2.4.3' - } - } - } - ] -}; diff --git a/package.json b/package.json index 8bfd85f15..5ccbedecc 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "build": "ember build", "start": "ember server", - "test": "ember try:testall" + "test": "ember test" }, "repository": "", "engines": { diff --git a/tests/unit/models/comment-report-test.js b/tests/unit/models/comment-report-test.js index ffb169518..fa95c604f 100644 --- a/tests/unit/models/comment-report-test.js +++ b/tests/unit/models/comment-report-test.js @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('comment-report', 'Unit | Model | comment report', { // Specify the other units that are required for this test. - needs: [] + needs: ['model:comment'] }); test('it exists', function(assert) { diff --git a/tests/unit/models/comment-test.js b/tests/unit/models/comment-test.js index 62c8a2709..933cd97df 100644 --- a/tests/unit/models/comment-test.js +++ b/tests/unit/models/comment-test.js @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('comment', 'Unit | Model | comment', { // Specify the other units that are required for this test. - needs: [] + needs: ['model:node', 'model:comment-report', 'model:user'] }); test('it exists', function(assert) { diff --git a/tests/unit/models/contributor-test.js b/tests/unit/models/contributor-test.js index 5caaffce3..68506cd3e 100644 --- a/tests/unit/models/contributor-test.js +++ b/tests/unit/models/contributor-test.js @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('contributor', 'Unit | Model | contributor', { // Specify the other units that are required for this test. - needs: [] + needs: ['model:user'] }); test('it exists', function(assert) { diff --git a/tests/unit/models/node-test.js b/tests/unit/models/node-test.js index 6652dfbe1..bea4dac90 100644 --- a/tests/unit/models/node-test.js +++ b/tests/unit/models/node-test.js @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('node', 'Unit | Model | node', { // Specify the other units that are required for this test. - needs: [] + needs: ['model:user', 'model:contributor', 'model:comment'] }); test('it exists', function(assert) { diff --git a/tests/unit/models/user-test.js b/tests/unit/models/user-test.js index ba211109a..6f3440c80 100644 --- a/tests/unit/models/user-test.js +++ b/tests/unit/models/user-test.js @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('user', 'Unit | Model | user', { // Specify the other units that are required for this test. - needs: [] + needs: ['model:node'] }); test('it exists', function(assert) { diff --git a/tests/unit/serializers/application-test.js b/tests/unit/serializers/application-test.js index 705e9eced..b72e6fc39 100644 --- a/tests/unit/serializers/application-test.js +++ b/tests/unit/serializers/application-test.js @@ -1,15 +1,12 @@ -import { moduleForModel, test } from 'ember-qunit'; +import { moduleForModel/*, test */} from 'ember-qunit'; moduleForModel('application', 'Unit | Serializer | application', { // Specify the other units that are required for this test. needs: ['serializer:application'] }); - +/* // Replace this with your real tests. test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); + }); +*/ From 35735c13a612b8fa3bf4bad6229e8c2e043d9b62 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 5 May 2016 16:56:03 -0400 Subject: [PATCH 022/959] Implement config hook in addon's index.js This allows for the addon to specify any settings it needs enabled in the consuming app. Also update the package.json (aplogies for the reformat). I had to move the non-core-Ember npm dependencies from dev to regular dependencies. It appears the consuming app will not install dev deps. Also add blueprints for .env files. Update the README to reflect this all! --- README.md | 39 ++----- blueprints/.jshintrc | 6 + .../env/files/.env-__name__ | 2 + blueprints/env/index.js | 15 +++ index.js | 47 +++++++- package.json | 110 +++++++++--------- tests/dummy/config/environment.js | 42 +------ 7 files changed, 134 insertions(+), 127 deletions(-) create mode 100644 blueprints/.jshintrc rename .env-dist => blueprints/env/files/.env-__name__ (81%) create mode 100644 blueprints/env/index.js diff --git a/README.md b/README.md index 0d2e3ffb7..9429ac04b 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,12 @@ This repo contains code for interacting with the OSF APIv2 inside of an Ember ap ## Using this code in an Ember app -1. Follow the instructions in **Installation** below +1. Clone the repository: `git clone https://github.com/CenterForOpenScience/ember-osf.git` 2. From the consuming Ember app: - a. `npm link ../ember-osf` - b. Edit the package.json to include: - ```json - ... - "devDependencies": { - ... - "ember-osf": "0.0.1", - ... - } - ... - ``` - c. Import code from ember-osf like: + a. install the addon and it's dependencies: `ember install ../ember-osf` + b. link the app for local development: `npm link ../ember-osf` + c. generate a .env (see 'Configuration' below): `ember generate env stage` + d. Import code from ember-osf like: ```javascript import Ember from 'ember'; import OsfLoginRouteMixin from 'ember-osf/mixins/osf-login-route'; @@ -38,22 +30,7 @@ this.store.findAll('node') ``` to fetch all nodes. -#### Ember Simple Auth config - -Specify that you want to use to osf-token authorizer in your app's enviornment.js like: -```javascript -... -var ENV = { - ... - 'ember-simple-auth': { - ... - authorizer: 'authorizer:osf-token' - } - ... -``` - - -## Installation +## Installation (for Development) * `git clone` this repository * `npm install` @@ -73,7 +50,7 @@ personal access token on your local OSF instance ([here](http://localhost:5000/s #### Create a .env -Next, depending on the environment you want to target, you will need to create the .env file. For: +Next, depending on the backend you want to target, you will need to create the .env file. For: - local: .env-local - staging: .env-stage - staging2: .env-stage2 @@ -81,7 +58,7 @@ Next, depending on the environment you want to target, you will need to create t To do this: ```bash -cp .env-dist .env- +ember g env ``` Edit the new .env and replace: diff --git a/blueprints/.jshintrc b/blueprints/.jshintrc new file mode 100644 index 000000000..33f4f6f4b --- /dev/null +++ b/blueprints/.jshintrc @@ -0,0 +1,6 @@ +{ + "predef": [ + "console" + ], + "strict": false +} diff --git a/.env-dist b/blueprints/env/files/.env-__name__ similarity index 81% rename from .env-dist rename to blueprints/env/files/.env-__name__ index 1af1996f0..4c232a135 100644 --- a/.env-dist +++ b/blueprints/env/files/.env-__name__ @@ -1,3 +1,5 @@ +# Environment variables: + OSF_CLIENT_ID= OSF_SCOPE=osf.full_read osf.full_write diff --git a/blueprints/env/index.js b/blueprints/env/index.js new file mode 100644 index 000000000..aec33ac41 --- /dev/null +++ b/blueprints/env/index.js @@ -0,0 +1,15 @@ +/*jshint node:true*/ +module.exports = { + description: '' + + // locals: function(options) { + // // Return custom template variables here. + // return { + // foo: options.entity.options.foo + // }; + // } + + // afterInstall: function(options) { + // // Perform extra work here. + // } +}; diff --git a/index.js b/index.js index bcd7d47b6..efab97a95 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,51 @@ /* jshint node: true */ 'use strict'; +var dotenv = require('dotenv'); module.exports = { - name: 'ember-osf' + name: 'ember-osf', + config: function(environment, ENV) { + dotenv.config({ + path:'.env-' + { + development: 'local', + test: 'test', + staging: 'stage', + staging2: 'stage2', + production: 'prod' + }[environment] + }); + + ENV.OSF = { + clientId: process.env.OSF_CLIENT_ID, + scope: process.env.OSF_SCOPE + }; + + if (environment === 'development') { + ENV.OSF.url = 'http://localhost:5000/'; + ENV.OSF.apiUrl = 'http://localhost:8000/v2/'; + ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; + + ENV.OSF.accessToken = process.env.OSF_ACCESS_TOKEN; + ENV.DEV = true; + } + if (environment === 'staging') { + ENV.OSF.url = 'https://staging.osf.io/'; + ENV.OSF.apiUrl = 'https://staging-api.osf.io/v2/'; + ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; + } + if (environment === 'staging2') { + ENV.OSF.url = 'https://staging2.osf.io/'; + ENV.OSF.apiUrl = 'https://staging2-api.osf.io/v2/'; + ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; + } + if (environment === 'production') { + ENV.OSF.url = 'https://osf.io/'; + ENV.OSF.apiUrl = 'https://api.osf.io/v2/'; + ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; + } + + ENV['ember-simple-auth'] = { + authorizer: 'authorizer:osf-token' + }; + } }; diff --git a/package.json b/package.json index 5ccbedecc..edf3942ef 100644 --- a/package.json +++ b/package.json @@ -1,57 +1,57 @@ { - "name": "ember-osf", - "version": "0.0.1", - "description": "Ember Data models for the OSF APIv2", - "directories": { - "doc": "doc", - "test": "tests" - }, - "scripts": { - "build": "ember build", - "start": "ember server", - "test": "ember test" - }, - "repository": "", - "engines": { - "node": ">= 0.10.0" - }, - "author": "", - "license": "MIT", - "devDependencies": { - "broccoli-asset-rev": "^2.2.0", - "dotenv": "^2.0.0", - "ember-ajax": "0.7.1", - "ember-cli": "^2.4.3", - "ember-cli-app-version": "^1.0.0", - "ember-cli-dependency-checker": "^1.2.0", - "ember-cli-htmlbars": "^1.0.1", - "ember-cli-htmlbars-inline-precompile": "^0.3.1", - "ember-cli-inject-live-reload": "^1.3.1", - "ember-cli-moment-shim": "1.1.0", - "ember-cli-qunit": "^1.2.1", - "ember-cli-release": "0.2.8", - "ember-cli-sri": "^2.0.0", - "ember-cli-uglify": "^1.2.0", - "ember-data": "^2.3.0", - "ember-disable-prototype-extensions": "^1.0.0", - "ember-disable-proxy-controllers": "^1.0.1", - "ember-export-application-global": "^1.0.4", - "ember-get-config": "0.0.2", - "ember-load-initializers": "0.5.1", - "ember-moment": "6.1.0", - "ember-resolver": "2.0.3", - "ember-simple-auth": "^1.0.1", - "loader": "2.1.0", - "loader.js": "4.0.3" - }, - "keywords": [ - "ember-addon" - ], - "dependencies": { - "ember-cli-babel": "^5.1.5", - "loader": "^2.1.0" - }, - "ember-addon": { - "configPath": "tests/dummy/config" - } + "name": "ember-osf", + "version": "0.0.1", + "description": "Ember Data models for the OSF APIv2", + "directories": { + "doc": "doc", + "test": "tests" + }, + "scripts": { + "build": "ember build", + "start": "ember server", + "test": "ember test" + }, + "repository": "", + "engines": { + "node": ">= 0.10.0" + }, + "author": "", + "license": "MIT", + "devDependencies": { + "broccoli-asset-rev": "^2.2.0", + "ember-ajax": "0.7.1", + "ember-cli": "^2.4.3", + "ember-cli-app-version": "^1.0.0", + "ember-cli-dependency-checker": "^1.2.0", + "ember-cli-htmlbars": "^1.0.1", + "ember-cli-htmlbars-inline-precompile": "^0.3.1", + "ember-cli-inject-live-reload": "^1.3.1", + "ember-cli-moment-shim": "1.1.0", + "ember-cli-qunit": "^1.2.1", + "ember-cli-release": "0.2.8", + "ember-cli-sri": "^2.0.0", + "ember-cli-uglify": "^1.2.0", + "ember-data": "^2.3.0", + "ember-disable-prototype-extensions": "^1.0.0", + "ember-disable-proxy-controllers": "^1.0.1", + "ember-export-application-global": "^1.0.4", + "ember-load-initializers": "0.5.1", + "ember-resolver": "2.0.3", + "loader": "2.1.0", + "loader.js": "4.0.3" + }, + "keywords": [ + "ember-addon" + ], + "dependencies": { + "ember-cli-babel": "^5.1.5", + "loader": "^2.1.0", + "ember-simple-auth": "1.1.0-beta.5", + "ember-get-config": "0.0.2", + "ember-moment": "6.1.0", + "dotenv": "^2.0.0" + }, + "ember-addon": { + "configPath": "tests/dummy/config" + } } diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index cc96491a8..e5c2430e6 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -1,17 +1,6 @@ /* jshint node: true */ -var dotenv = require('dotenv'); -var path = require('path'); module.exports = function(environment) { - dotenv.config({ - path:'.env-' + { - development: 'local', - test: 'test', - staging: 'stage', - staging2: 'stage2', - production: 'prod' - }[environment] - }); var ENV = { modulePrefix: 'dummy', @@ -24,19 +13,13 @@ module.exports = function(environment) { // e.g. 'with-controller': true } }, - APP: { // Here you can pass flags/options to your application instance // when it is created }, - OSF: { - clientId: process.env.OSF_CLIENT_ID, - scope: process.env.OSF_SCOPE - }, 'ember-simple-auth': { authenticationRoute: 'login', - routeAfterAuthentication: 'index', - authorizer: 'authorizer:osf-token' + routeAfterAuthentication: 'index' } }; @@ -46,14 +29,6 @@ module.exports = function(environment) { //ENV.APP.LOG_TRANSITIONS = true; //ENV.APP.LOG_TRANSITIONS_INTERNAL = true; //ENV.APP.LOG_VIEW_LOOKUPS = true; - - - ENV.OSF.url = 'http://localhost:5000/'; - ENV.OSF.apiUrl = 'http://localhost:8000/v2/'; - ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; - - ENV.OSF.accessToken = process.env.OSF_ACCESS_TOKEN; - ENV.DEV = true; } if (environment === 'test') { @@ -69,26 +44,13 @@ module.exports = function(environment) { } if (environment === 'staging') { - ENV.APP.LOG_TRANSITIONS = true; - ENV.OSF.url = 'https://staging.osf.io/'; - ENV.OSF.apiUrl = 'https://staging-api.osf.io/v2/'; - ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; } if (environment === 'staging2') { - ENV.APP.LOG_TRANSITIONS = true; - ENV.OSF.url = 'https://staging2.osf.io/'; - ENV.OSF.apiUrl = 'https://staging2-api.osf.io/v2/'; - ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; } - if (environment === 'production') { - - ENV.OSF.url = 'https://osf.io/'; - ENV.OSF.apiUrl = 'https://api.osf.io/v2/'; - ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; - } + if (environment === 'production') {} return ENV; }; From 61b9e92bd6e79e8abc27c4541d9b422c906fd235 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 5 May 2016 17:07:46 -0400 Subject: [PATCH 023/959] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9429ac04b..b5afac07e 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ This repo contains code for interacting with the OSF APIv2 inside of an Ember ap 1. Clone the repository: `git clone https://github.com/CenterForOpenScience/ember-osf.git` 2. From the consuming Ember app: - a. install the addon and it's dependencies: `ember install ../ember-osf` - b. link the app for local development: `npm link ../ember-osf` - c. generate a .env (see 'Configuration' below): `ember generate env stage` - d. Import code from ember-osf like: + - install the addon and it's dependencies: `ember install ../ember-osf` + - link the app for local development: `npm link ../ember-osf` + - generate a .env (see 'Configuration' below): `ember generate env stage` + - Import code from ember-osf like: ```javascript import Ember from 'ember'; import OsfLoginRouteMixin from 'ember-osf/mixins/osf-login-route'; From f93809a5921756340668e025dbca11b59cddf497 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 5 May 2016 21:46:03 -0400 Subject: [PATCH 024/959] Remove moment and bootstrap dependency --- bower.json | 3 +-- package.json | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 35f7d58d2..8f56a772e 100644 --- a/bower.json +++ b/bower.json @@ -4,7 +4,6 @@ "ember": "~2.4.3", "ember-cli-shims": "0.1.1", "ember-cli-test-loader": "0.2.2", - "ember-qunit-notifications": "0.1.0", - "bootstrap": "^3.3.6" + "ember-qunit-notifications": "0.1.0" } } diff --git a/package.json b/package.json index edf3942ef..b3c4657fd 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "ember-cli-htmlbars": "^1.0.1", "ember-cli-htmlbars-inline-precompile": "^0.3.1", "ember-cli-inject-live-reload": "^1.3.1", - "ember-cli-moment-shim": "1.1.0", "ember-cli-qunit": "^1.2.1", "ember-cli-release": "0.2.8", "ember-cli-sri": "^2.0.0", From 84cff3fda1847cc31fc6cd48bf6cb4b8660bc64a Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 5 May 2016 21:57:09 -0400 Subject: [PATCH 025/959] Move bootstrap to devDependency It's only used in the dummy app --- bower.json | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bower.json b/bower.json index 8f56a772e..b9f7800fd 100644 --- a/bower.json +++ b/bower.json @@ -1,9 +1,12 @@ { - "name": "ember-osf", - "dependencies": { - "ember": "~2.4.3", - "ember-cli-shims": "0.1.1", - "ember-cli-test-loader": "0.2.2", - "ember-qunit-notifications": "0.1.0" - } + "name": "ember-osf", + "dependencies": { + "ember": "~2.4.3", + "ember-cli-shims": "0.1.1", + "ember-cli-test-loader": "0.2.2", + "ember-qunit-notifications": "0.1.0" + }, + "devDependencies": { + "bootstrap": "^3.3.6" + } } From f7d7028bfcd1a715fb59182261a84c02c26a30b7 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 6 May 2016 15:24:27 -0400 Subject: [PATCH 026/959] Re-add support for personal access tokens This is needed for local development --- addon/mixins/osf-login-route.js | 26 +++++++++++++++++--------- index.js | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/addon/mixins/osf-login-route.js b/addon/mixins/osf-login-route.js index 897250dd1..ba1d3bc12 100644 --- a/addon/mixins/osf-login-route.js +++ b/addon/mixins/osf-login-route.js @@ -1,19 +1,27 @@ import Ember from 'ember'; import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin'; +import config from 'ember-get-config'; + export default Ember.Mixin.create(UnauthenticatedRouteMixin, { session: Ember.inject.service(), beforeModel() { - // Acquire an OSF access token, then exchange it for a Jam token - var hash = window.location.hash.substring(1).split('&').map(function(str) { - return this[str.split('=')[0]] = str.split('=')[1], this; - }.bind({}))[0]; - if (!hash || !hash.access_token) { - return null; + var accessToken; + if (config.OSF.local) { + accessToken = config.OSF.accessToken; + } else { + // Acquire an OSF access token, then exchange it for a Jam token + var hash = window.location.hash.substring(1).split('&').map(function(str) { + return this[str.split('=')[0]] = str.split('=')[1], this; + }.bind({}))[0]; + if (!hash || !hash.access_token) { + return null; + } + window.location.hash = ''; + accessToken = hash.access_token; } - window.location.hash = ''; - var accessToken = hash.access_token; - return this.get('session').authenticate('authenticator:osf-token', accessToken) + + return this.get('session').authenticate('authenticator:osf-token', accessToken) .then(() => this.transitionTo('index')); } }); diff --git a/index.js b/index.js index efab97a95..e886bb362 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ module.exports = { ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; ENV.OSF.accessToken = process.env.OSF_ACCESS_TOKEN; - ENV.DEV = true; + ENV.OSF.local = true; } if (environment === 'staging') { ENV.OSF.url = 'https://staging.osf.io/'; From 7d79f2015fc7ab1ebdf0f6136cc522ee07a4db1f Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 6 May 2016 15:53:59 -0400 Subject: [PATCH 027/959] Install ember-cli-mirage --- .jshintrc | 1 + tests/.jshintrc | 1 + tests/dummy/app/mirage/config.js | 82 +++++++++++++++++++++ tests/dummy/app/mirage/factories/base.js | 3 + tests/dummy/app/mirage/scenarios/default.js | 7 ++ 5 files changed, 94 insertions(+) create mode 100644 tests/dummy/app/mirage/config.js create mode 100644 tests/dummy/app/mirage/factories/base.js create mode 100644 tests/dummy/app/mirage/scenarios/default.js diff --git a/.jshintrc b/.jshintrc index 08096effa..2f30d1604 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,5 +1,6 @@ { "predef": [ + "server", "document", "window", "-Promise" diff --git a/tests/.jshintrc b/tests/.jshintrc index 6ec0b7c15..4f9f51d89 100644 --- a/tests/.jshintrc +++ b/tests/.jshintrc @@ -1,5 +1,6 @@ { "predef": [ + "server", "document", "window", "location", diff --git a/tests/dummy/app/mirage/config.js b/tests/dummy/app/mirage/config.js new file mode 100644 index 000000000..d006425e9 --- /dev/null +++ b/tests/dummy/app/mirage/config.js @@ -0,0 +1,82 @@ +export default function() { + + // These comments are here to help you get started. Feel free to delete them. + + /* + Config (with defaults). + + Note: these only affect routes defined *after* them! + */ + // this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server + // this.namespace = ''; // make this `api`, for example, if your API is namespaced + // this.timing = 400; // delay for each request, automatically set to 0 during testing + + /* + Route shorthand cheatsheet + */ + /* + GET shorthands + + // Collections + this.get('/contacts'); + this.get('/contacts', 'users'); + this.get('/contacts', ['contacts', 'addresses']); + + // Single objects + this.get('/contacts/:id'); + this.get('/contacts/:id', 'user'); + this.get('/contacts/:id', ['contact', 'addresses']); + */ + + /* + POST shorthands + + this.post('/contacts'); + this.post('/contacts', 'user'); // specify the type of resource to be created + */ + + /* + PUT shorthands + + this.put('/contacts/:id'); + this.put('/contacts/:id', 'user'); // specify the type of resource to be updated + */ + + /* + DELETE shorthands + + this.del('/contacts/:id'); + this.del('/contacts/:id', 'user'); // specify the type of resource to be deleted + + // Single object + related resources. Make sure parent resource is first. + this.del('/contacts/:id', ['contact', 'addresses']); + */ + + /* + Function fallback. Manipulate data in the db via + + - db.{collection} + - db.{collection}.find(id) + - db.{collection}.where(query) + - db.{collection}.update(target, attrs) + - db.{collection}.remove(target) + + // Example: return a single object with related models + this.get('/contacts/:id', function(db, request) { + var contactId = +request.params.id; + + return { + contact: db.contacts.find(contactId), + addresses: db.addresses.where({contact_id: contactId}) + }; + }); + + */ +} + +/* +You can optionally export a config that is only loaded during tests +export function testConfig() { + +} +*/ diff --git a/tests/dummy/app/mirage/factories/base.js b/tests/dummy/app/mirage/factories/base.js new file mode 100644 index 000000000..e483635d1 --- /dev/null +++ b/tests/dummy/app/mirage/factories/base.js @@ -0,0 +1,3 @@ +import Mirage/*, {faker}*/ from 'ember-cli-mirage'; + +export default Mirage.Factory.extend({}); diff --git a/tests/dummy/app/mirage/scenarios/default.js b/tests/dummy/app/mirage/scenarios/default.js new file mode 100644 index 000000000..e07271cc9 --- /dev/null +++ b/tests/dummy/app/mirage/scenarios/default.js @@ -0,0 +1,7 @@ +export default function(/* server */) { + + // Seed your development database using your factories. This + // data will not be loaded in your tests. + + // server.createList('contact', 10); +} From 603175fc470a22b1cef9efe1cff6af5f2944fe54 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 6 May 2016 15:54:30 -0400 Subject: [PATCH 028/959] Reformat requirements files --- bower.json | 23 ++++++----- package.json | 109 ++++++++++++++++++++++++++------------------------- 2 files changed, 68 insertions(+), 64 deletions(-) diff --git a/bower.json b/bower.json index b9f7800fd..c435c94aa 100644 --- a/bower.json +++ b/bower.json @@ -1,12 +1,15 @@ { - "name": "ember-osf", - "dependencies": { - "ember": "~2.4.3", - "ember-cli-shims": "0.1.1", - "ember-cli-test-loader": "0.2.2", - "ember-qunit-notifications": "0.1.0" - }, - "devDependencies": { - "bootstrap": "^3.3.6" - } + "name": "ember-osf", + "dependencies": { + "ember": "~2.4.3", + "ember-cli-shims": "0.1.1", + "ember-cli-test-loader": "0.2.1", + "ember-qunit-notifications": "0.1.0", + "Faker": "~3.0.0", + "pretender": "~0.10.1", + "lodash": "~3.7.0" + }, + "devDependencies": { + "bootstrap": "^3.3.6" + } } diff --git a/package.json b/package.json index b3c4657fd..078df3423 100644 --- a/package.json +++ b/package.json @@ -1,56 +1,57 @@ { - "name": "ember-osf", - "version": "0.0.1", - "description": "Ember Data models for the OSF APIv2", - "directories": { - "doc": "doc", - "test": "tests" - }, - "scripts": { - "build": "ember build", - "start": "ember server", - "test": "ember test" - }, - "repository": "", - "engines": { - "node": ">= 0.10.0" - }, - "author": "", - "license": "MIT", - "devDependencies": { - "broccoli-asset-rev": "^2.2.0", - "ember-ajax": "0.7.1", - "ember-cli": "^2.4.3", - "ember-cli-app-version": "^1.0.0", - "ember-cli-dependency-checker": "^1.2.0", - "ember-cli-htmlbars": "^1.0.1", - "ember-cli-htmlbars-inline-precompile": "^0.3.1", - "ember-cli-inject-live-reload": "^1.3.1", - "ember-cli-qunit": "^1.2.1", - "ember-cli-release": "0.2.8", - "ember-cli-sri": "^2.0.0", - "ember-cli-uglify": "^1.2.0", - "ember-data": "^2.3.0", - "ember-disable-prototype-extensions": "^1.0.0", - "ember-disable-proxy-controllers": "^1.0.1", - "ember-export-application-global": "^1.0.4", - "ember-load-initializers": "0.5.1", - "ember-resolver": "2.0.3", - "loader": "2.1.0", - "loader.js": "4.0.3" - }, - "keywords": [ - "ember-addon" - ], - "dependencies": { - "ember-cli-babel": "^5.1.5", - "loader": "^2.1.0", - "ember-simple-auth": "1.1.0-beta.5", - "ember-get-config": "0.0.2", - "ember-moment": "6.1.0", - "dotenv": "^2.0.0" - }, - "ember-addon": { - "configPath": "tests/dummy/config" - } + "name": "ember-osf", + "version": "0.0.1", + "description": "Ember Data models for the OSF APIv2", + "directories": { + "doc": "doc", + "test": "tests" + }, + "scripts": { + "build": "ember build", + "start": "ember server", + "test": "ember test" + }, + "repository": "", + "engines": { + "node": ">= 0.10.0" + }, + "author": "", + "license": "MIT", + "devDependencies": { + "broccoli-asset-rev": "^2.2.0", + "ember-ajax": "0.7.1", + "ember-cli": "^2.4.3", + "ember-cli-app-version": "^1.0.0", + "ember-cli-dependency-checker": "^1.2.0", + "ember-cli-htmlbars": "^1.0.1", + "ember-cli-htmlbars-inline-precompile": "^0.3.1", + "ember-cli-inject-live-reload": "^1.3.1", + "ember-cli-mirage": "0.1.13", + "ember-cli-qunit": "^1.2.1", + "ember-cli-release": "0.2.8", + "ember-cli-sri": "^2.0.0", + "ember-cli-uglify": "^1.2.0", + "ember-data": "^2.3.0", + "ember-disable-prototype-extensions": "^1.0.0", + "ember-disable-proxy-controllers": "^1.0.1", + "ember-export-application-global": "^1.0.4", + "ember-load-initializers": "0.5.1", + "ember-resolver": "2.0.3", + "loader": "2.1.0", + "loader.js": "4.0.3" + }, + "keywords": [ + "ember-addon" + ], + "dependencies": { + "ember-cli-babel": "^5.1.5", + "loader": "^2.1.0", + "ember-simple-auth": "1.1.0-beta.5", + "ember-get-config": "0.0.2", + "ember-moment": "6.1.0", + "dotenv": "^2.0.0" + }, + "ember-addon": { + "configPath": "tests/dummy/config" + } } From b5d1edc11eb16594366fcd569b16399791c8fb9e Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 6 May 2016 15:54:47 -0400 Subject: [PATCH 029/959] WIP serializers unit tests --- addon/serializers/application.js | 4 ++ tests/unit/models/base-test.js | 8 +--- tests/unit/serializers/application-test.js | 46 ++++++++++++++++++---- tests/unit/serializers/node-test.js | 15 +++++++ 4 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 tests/unit/serializers/node-test.js diff --git a/addon/serializers/application.js b/addon/serializers/application.js index d8cdbd6ad..e1fa924c2 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -14,6 +14,10 @@ export default DS.JSONAPISerializer.extend({ if (record.links) { record.attributes.links = record.links; } + if (record.embeds) { + // TODO, actually merge in embedded data? + record.attributes.embeds = record.embeds; + } return record; }, normalizeSingleResponse(_, __, payload) { diff --git a/tests/unit/models/base-test.js b/tests/unit/models/base-test.js index 3065a6f45..c40c5114b 100644 --- a/tests/unit/models/base-test.js +++ b/tests/unit/models/base-test.js @@ -1,12 +1,6 @@ -import { moduleForModel, test } from 'ember-qunit'; +import { moduleForModel /*, test*/ } from 'ember-qunit'; moduleForModel('base', 'Unit | Model | base', { // Specify the other units that are required for this test. needs: [] }); - -test('it exists', function(assert) { - let model = this.subject(); - // let store = this.store(); - assert.ok(!!model); -}); diff --git a/tests/unit/serializers/application-test.js b/tests/unit/serializers/application-test.js index b72e6fc39..ae5fc74a9 100644 --- a/tests/unit/serializers/application-test.js +++ b/tests/unit/serializers/application-test.js @@ -1,12 +1,42 @@ -import { moduleForModel/*, test */} from 'ember-qunit'; +import { moduleForModel, test } from 'ember-qunit'; +import { faker } from 'ember-cli-mirage'; -moduleForModel('application', 'Unit | Serializer | application', { - // Specify the other units that are required for this test. +moduleForModel('base', 'Unit | Serializer | application', { needs: ['serializer:application'] }); -/* -// Replace this with your real tests. -test('it serializes records', function(assert) { - + +test('#_normalizeRecord adds links to attributes if included in payload', function(assert) { + let payload = { + id: faker.random.uuid(), + type: 'base', + attributes: { + key: 'value' + }, + links: { + html: faker.internet.url() + } + }; + + let serializer = this.container.lookup('serializer:application'); + let normalized = serializer._normalizeRecord(payload); + + assert.equal(normalized.attributes.links, payload.links); +}); +test('#_normalizeRecord adds links to attributes if included in payload', function(assert) { + let payload = { + id: faker.random.uuid(), + attributes: { + key: 'value' + }, + embeds: { + embedded: { + data: [faker.random.arrayElement()] + } + } + }; + + let serializer = this.container.lookup('serializer:application'); + let normalized = serializer._normalizeRecord(payload); + + assert.equal(normalized.attributes.embeds, payload.embeds); }); -*/ diff --git a/tests/unit/serializers/node-test.js b/tests/unit/serializers/node-test.js new file mode 100644 index 000000000..b79ba7400 --- /dev/null +++ b/tests/unit/serializers/node-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('node', 'Unit | Serializer | node', { + // Specify the other units that are required for this test. + needs: ['serializer:node'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); From 35fd1a11db6fe5d3271b6ccd0d324ea77c2771a2 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 12:19:01 -0400 Subject: [PATCH 030/959] Switch to using config module for local configs --- .gitignore | 6 +----- index.js | 30 +++++++++++++----------------- package.json | 2 ++ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 0cab8edcb..399b6f91f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,8 +16,4 @@ npm-debug.log testem.log -.env -.env-local -.env-stage* -.env-prod - +*local.yml diff --git a/index.js b/index.js index e886bb362..510388ca9 100644 --- a/index.js +++ b/index.js @@ -1,44 +1,40 @@ /* jshint node: true */ 'use strict'; -var dotenv = require('dotenv'); +var config = require('config'); module.exports = { name: 'ember-osf', config: function(environment, ENV) { - dotenv.config({ - path:'.env-' + { - development: 'local', - test: 'test', - staging: 'stage', - staging2: 'stage2', - production: 'prod' - }[environment] - }); + let BACKEND = process.env.BACKEND || 'local'; + if (!config.has(BACKEND)) { + throw new Error(`WARNING: you have specified a backend: ${BACKEND} that you have not configured in your local.yml`); + } + let SETTINGS = config.get(BACKEND); ENV.OSF = { - clientId: process.env.OSF_CLIENT_ID, - scope: process.env.OSF_SCOPE + clientId: SETTINGS.CLIENT_ID, + scope: SETTINGS.OAUTH_SCOPES }; - if (environment === 'development') { + if (BACKEND === 'local') { ENV.OSF.url = 'http://localhost:5000/'; ENV.OSF.apiUrl = 'http://localhost:8000/v2/'; ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; - ENV.OSF.accessToken = process.env.OSF_ACCESS_TOKEN; + ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; ENV.OSF.local = true; } - if (environment === 'staging') { + if (BACKEND === 'stage') { ENV.OSF.url = 'https://staging.osf.io/'; ENV.OSF.apiUrl = 'https://staging-api.osf.io/v2/'; ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; } - if (environment === 'staging2') { + if (BACKEND === 'stage2') { ENV.OSF.url = 'https://staging2.osf.io/'; ENV.OSF.apiUrl = 'https://staging2-api.osf.io/v2/'; ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; } - if (environment === 'production') { + if (BACKEND === 'prod') { ENV.OSF.url = 'https://osf.io/'; ENV.OSF.apiUrl = 'https://api.osf.io/v2/'; ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; diff --git a/package.json b/package.json index 078df3423..1fe18ea24 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "license": "MIT", "devDependencies": { "broccoli-asset-rev": "^2.2.0", + "config": "^1.20.1", "ember-ajax": "0.7.1", "ember-cli": "^2.4.3", "ember-cli-app-version": "^1.0.0", @@ -37,6 +38,7 @@ "ember-export-application-global": "^1.0.4", "ember-load-initializers": "0.5.1", "ember-resolver": "2.0.3", + "js-yaml": "^3.6.0", "loader": "2.1.0", "loader.js": "4.0.3" }, From 212b3f798edb6cc766517a31a5a551c5fe4f8807 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 9 May 2016 13:17:18 -0400 Subject: [PATCH 031/959] Consistent indentation --- .editorconfig | 6 +++--- addon/adapters/node.js | 4 ++-- addon/serializers/application.js | 18 ++++++++-------- tests/dummy/app/router.js | 2 +- tests/dummy/app/routes/nodes.js | 2 +- tests/dummy/app/routes/nodes/detail.js | 2 +- tests/dummy/app/templates/nodes/index.hbs | 26 +++++++++++------------ 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9a13d9b1e..3ef6636ee 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,15 +20,15 @@ indent_size = 4 [*.hbs] insert_final_newline = false indent_style = space -indent_size = 2 +indent_size = 4 [*.css] indent_style = space -indent_size = 2 +indent_size = 4 [*.html] indent_style = space -indent_size = 2 +indent_size = 4 [*.{diff,md}] trim_trailing_whitespace = false diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 6e925e874..5ce0d304d 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -2,7 +2,7 @@ import ApplicationAdapter from './application'; export default ApplicationAdapter.extend({ buildURL() { - // Embed contributors - return `${this._super(...arguments)}?embed=contributors`; + // Embed contributors + return `${this._super(...arguments)}?embed=contributors`; } }); diff --git a/addon/serializers/application.js b/addon/serializers/application.js index d8cdbd6ad..5b752e78d 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -10,11 +10,11 @@ export default DS.JSONAPISerializer.extend({ return normalized; }, _normalizeRecord(record) { - record.attributes = this._normalizeAttributes(record.attributes); - if (record.links) { - record.attributes.links = record.links; - } - return record; + record.attributes = this._normalizeAttributes(record.attributes); + if (record.links) { + record.attributes.links = record.links; + } + return record; }, normalizeSingleResponse(_, __, payload) { payload.data = this._normalizeRecord(payload.data); @@ -25,12 +25,12 @@ export default DS.JSONAPISerializer.extend({ return this._super(...arguments); }, keyForAttribute(key) { - return Ember.String.camelize(key); + return Ember.String.camelize(key); }, serializeIntoHash(/*hash, typeClass, snapshot, options*/) { - // Don't send links as part of hash - // TODO - return this._super(...arguments); + // Don't send links as part of hash + // TODO + return this._super(...arguments); } }); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 5a1c57bf8..db980d984 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -8,7 +8,7 @@ const Router = Ember.Router.extend({ Router.map(function() { this.route('index', {path: '/'}); this.route('nodes', function() { - this.route('detail', {path: '/:node_id'}); + this.route('detail', {path: '/:node_id'}); }); this.route('login'); }); diff --git a/tests/dummy/app/routes/nodes.js b/tests/dummy/app/routes/nodes.js index 427ddbb94..4d5032adf 100644 --- a/tests/dummy/app/routes/nodes.js +++ b/tests/dummy/app/routes/nodes.js @@ -6,6 +6,6 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { session: Ember.inject.service(), model() { const user = this.modelFor('application'); - return user.get('nodes'); + return user.get('nodes'); // Fetch from `/users/me/nodes/` } }); diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index b711cbe5f..ccd983323 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -2,6 +2,6 @@ import Ember from 'ember'; export default Ember.Route.extend({ model(params) { - return this.store.findRecord('node', params.node_id); + return this.store.findRecord('node', params.node_id); } }); diff --git a/tests/dummy/app/templates/nodes/index.hbs b/tests/dummy/app/templates/nodes/index.hbs index 6058e0729..6234c45dd 100644 --- a/tests/dummy/app/templates/nodes/index.hbs +++ b/tests/dummy/app/templates/nodes/index.hbs @@ -1,16 +1,16 @@

My Nodes

{{#each model as |node|}} -
-
-

{{node.title}}

-

{{node.category}}

-

{{moment-format node.dateCreated}}

-

{{moment-format node.dateModified}}

-

- - View on OSF - - {{link-to 'Detail' 'nodes.detail' node.id class="btn btn-primary"}} -

-
+
+
+

{{node.title}}

+

{{node.category}}

+

{{moment-format node.dateCreated}}

+

{{moment-format node.dateModified}}

+

+ + View on OSF + + {{link-to 'Detail' 'nodes.detail' node.id class="btn btn-primary"}} +

+
{{/each}} From 6f3d0e0fde688da74045dc590e9483c2a329270c Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 9 May 2016 13:17:42 -0400 Subject: [PATCH 032/959] Make .env ignores general --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 0cab8edcb..c0799bbff 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,5 @@ npm-debug.log testem.log .env -.env-local -.env-stage* -.env-prod +.env-* From f9a63fed261e727b86c0694e7811e6ea1cd4e1e3 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 14:04:22 -0400 Subject: [PATCH 033/959] Fix moment dependencies --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1fe18ea24..0f2b8b2c3 100644 --- a/package.json +++ b/package.json @@ -28,19 +28,23 @@ "ember-cli-htmlbars-inline-precompile": "^0.3.1", "ember-cli-inject-live-reload": "^1.3.1", "ember-cli-mirage": "0.1.13", + "ember-cli-moment-shim": "1.1.0", "ember-cli-qunit": "^1.2.1", "ember-cli-release": "0.2.8", "ember-cli-sri": "^2.0.0", "ember-cli-uglify": "^1.2.0", "ember-data": "^2.3.0", + "ember-data-url-templates": "0.1.1", "ember-disable-prototype-extensions": "^1.0.0", "ember-disable-proxy-controllers": "^1.0.1", "ember-export-application-global": "^1.0.4", "ember-load-initializers": "0.5.1", + "ember-moment": "6.1.0", "ember-resolver": "2.0.3", "js-yaml": "^3.6.0", "loader": "2.1.0", - "loader.js": "4.0.3" + "loader.js": "4.0.3", + "moment": "^2.13.0" }, "keywords": [ "ember-addon" From 674630b54a4e0dc4881c5e38d8115b35287fa2a1 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 14:04:46 -0400 Subject: [PATCH 034/959] User ember-data-url-templates --- addon/adapters/application.js | 15 +++++++-------- addon/models/node.js | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/addon/adapters/application.js b/addon/adapters/application.js index 9f4b34755..c16a9618f 100644 --- a/addon/adapters/application.js +++ b/addon/adapters/application.js @@ -1,18 +1,17 @@ import Ember from 'ember'; import DS from 'ember-data'; import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; +import UrlTemplates from "ember-data-url-templates"; import config from 'ember-get-config'; -export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { +export default DS.JSONAPIAdapter.extend(UrlTemplates, DataAdapterMixin, { authorizer: 'authorizer:osf-token', - host: config.OSF.apiUrl, - pathForType: Ember.String.pluralize, - urlForFindRecord (id, modelName/*, snapshot*/) { - return `${this.get('host')}${Ember.String.pluralize(modelName)}/${id}/`; - }, - urlForFindAll (modelName) { - return `${this.get('host')}${Ember.String.pluralize(modelName)}/`; + urlTemplate: '{+host}{modelName}{/id}/', + urlSegments: { + modelName (modelName) { + return Ember.String.pluralize(modelName); + } } }); diff --git a/addon/models/node.js b/addon/models/node.js index 069c2313b..5985e35d4 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -7,7 +7,7 @@ export default OsfModel.extend({ description: DS.attr('string'), category: DS.attr('string'), - currentUserPermissions: DS.attr(''), + currentUserPermissions: DS.attr('string'), fork: DS.attr('boolean'), collection: DS.attr('boolean'), From db2e847525466b01cecee98665bdf38b2a9367eb Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 14:05:03 -0400 Subject: [PATCH 035/959] Test node adapter overrides --- tests/dummy/app/routes/nodes.js | 9 +++++++-- tests/unit/adapters/node-test.js | 11 ++++++----- tests/unit/serializers/node-test.js | 15 --------------- 3 files changed, 13 insertions(+), 22 deletions(-) delete mode 100644 tests/unit/serializers/node-test.js diff --git a/tests/dummy/app/routes/nodes.js b/tests/dummy/app/routes/nodes.js index 427ddbb94..67d18dcbc 100644 --- a/tests/dummy/app/routes/nodes.js +++ b/tests/dummy/app/routes/nodes.js @@ -5,7 +5,12 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { store: Ember.inject.service(), session: Ember.inject.service(), model() { - const user = this.modelFor('application'); - return user.get('nodes'); + let user = this.modelFor('application'); + if(user) { + return user.get('nodes'); + } + else { + return this.get('store').findRecord('user', 'me').then(user => user.get('nodes')); + } } }); diff --git a/tests/unit/adapters/node-test.js b/tests/unit/adapters/node-test.js index 2f8dd17ce..005d54b65 100644 --- a/tests/unit/adapters/node-test.js +++ b/tests/unit/adapters/node-test.js @@ -2,11 +2,12 @@ import { moduleFor, test } from 'ember-qunit'; moduleFor('adapter:node', 'Unit | Adapter | node', { // Specify the other units that are required for this test. - // needs: ['serializer:foo'] + needs: ['model:node'] }); -// Replace this with your real tests. -test('it exists', function(assert) { - let adapter = this.subject(); - assert.ok(adapter); +test('it embeds contributors', function(assert) { + let adapter = this.subject(); + + let url = adapter.buildURL('nodes', null, null, 'GET', null); + assert.ok(adapter); }); diff --git a/tests/unit/serializers/node-test.js b/tests/unit/serializers/node-test.js deleted file mode 100644 index b79ba7400..000000000 --- a/tests/unit/serializers/node-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('node', 'Unit | Serializer | node', { - // Specify the other units that are required for this test. - needs: ['serializer:node'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); From eb0c2ed1564417f203b6c3b39f0bf7839cb8d97e Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 14:57:51 -0400 Subject: [PATCH 036/959] Add blueprint for local.yml; update README --- .gitignore | 2 +- README.md | 32 ++++++++++--------- .../files/config/__name__.yml | 19 +++++++++++ .../{env => ember-osf-settings}/index.js | 0 blueprints/env/files/.env-__name__ | 6 ---- 5 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 blueprints/ember-osf-settings/files/config/__name__.yml rename blueprints/{env => ember-osf-settings}/index.js (100%) delete mode 100644 blueprints/env/files/.env-__name__ diff --git a/.gitignore b/.gitignore index 399b6f91f..f3e1637c8 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,4 @@ npm-debug.log testem.log -*local.yml +config/*.yml diff --git a/README.md b/README.md index b5afac07e..0f6fea917 100644 --- a/README.md +++ b/README.md @@ -48,29 +48,31 @@ For local development, you will need to be running the [OSF APIv2](https://githu To connect to the APIv2 while using [fakecas](https://github.com/CenterForOpenScience/osf.io#running-the-osf), you will need to generate a personal access token on your local OSF instance ([here](http://localhost:5000/settings/tokens/-- go ahead and grant access to all scopes)). -#### Create a .env - -Next, depending on the backend you want to target, you will need to create the .env file. For: -- local: .env-local -- staging: .env-stage -- staging2: .env-stage2 -- production: .env-prod +#### Create a local settings file To do this: ```bash -ember g env +ember g ember-osf-settings `echo $HOSTNAME` ``` -Edit the new .env and replace: -- `` with the client id of your developer application -- `` with the newly generated token (if applicable) - -**Note**: For development, we reccomend point your local app to our staging servers: `ember s --environment staging` +Edit the new file (installed in the config directory) and set: +- `CLIENT_ID` to the client id of your developer application +- `PERSONAL_ACCESS_TOKEN` to the newly generated token (if applicable, optional for staging development) ## Running -* `ember server` -* Visit your app at http://localhost:4200. +First, decide which backend you would like to target. Typically we reccomend developers use either our staging or test servers: +- staging (`stage`): contains bleeding edge features, but less stable +- test (`test`): matches production features, very stable + +Other options include: +- local (`local`): for developers running the OSF stack locally +- staging2 (`stage2`): another version of staging using running a specific feature branch + +Then (using staging as an example) run: +`BACKEND=stage ember s` + +and visit your app at http://localhost:4200. **Note:** This runs the dummy app contained in /tests/dummy diff --git a/blueprints/ember-osf-settings/files/config/__name__.yml b/blueprints/ember-osf-settings/files/config/__name__.yml new file mode 100644 index 000000000..cdfa042ac --- /dev/null +++ b/blueprints/ember-osf-settings/files/config/__name__.yml @@ -0,0 +1,19 @@ +# local: +# CLIENT_ID: null +# PERSONAL_ACCESS_TOKEN: null +# OAUTH_SCOPES: osf.full_read osf.full_write + +stage: + CLIENT_ID: null + PERSONAL_ACCESS_TOKEN: null + OAUTH_SCOPES: osf.full_read osf.full_write + +# stage2: +# CLIENT_ID: null +# PERSONAL_ACCESS_TOKEN: null +# OAUTH_SCOPES: osf.full_read osf.full_write + +# test: +# CLIENT_ID: null +# PERSONAL_ACCESS_TOKEN: null +# OAUTH_SCOPES: osf.full_read osf.full_write diff --git a/blueprints/env/index.js b/blueprints/ember-osf-settings/index.js similarity index 100% rename from blueprints/env/index.js rename to blueprints/ember-osf-settings/index.js diff --git a/blueprints/env/files/.env-__name__ b/blueprints/env/files/.env-__name__ deleted file mode 100644 index 4c232a135..000000000 --- a/blueprints/env/files/.env-__name__ +++ /dev/null @@ -1,6 +0,0 @@ -# Environment variables: - -OSF_CLIENT_ID= -OSF_SCOPE=osf.full_read osf.full_write - -OSF_ACCESS_TOKEN= From a3e517304182f566d9407243826e1a5eb0836f22 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 15:06:21 -0400 Subject: [PATCH 037/959] Fix the failing test --- tests/unit/adapters/node-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/adapters/node-test.js b/tests/unit/adapters/node-test.js index 005d54b65..abea40157 100644 --- a/tests/unit/adapters/node-test.js +++ b/tests/unit/adapters/node-test.js @@ -8,6 +8,6 @@ moduleFor('adapter:node', 'Unit | Adapter | node', { test('it embeds contributors', function(assert) { let adapter = this.subject(); - let url = adapter.buildURL('nodes', null, null, 'GET', null); + //let url = adapter.buildURL('nodes', null, null, 'GET', null); assert.ok(adapter); }); From e7976f66c362b6c12f807551ff5c9a2391b7a29a Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 15:18:52 -0400 Subject: [PATCH 038/959] Use pods --- .ember-cli | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.ember-cli b/.ember-cli index ee64cfed2..e0e1c5ce1 100644 --- a/.ember-cli +++ b/.ember-cli @@ -5,5 +5,6 @@ Setting `disableAnalytics` to true will prevent any data from being sent. */ - "disableAnalytics": false + "disableAnalytics": false, + "pod": true } From a4cff467578733be26915f75c1a05e3b16e6a687 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 15:28:03 -0400 Subject: [PATCH 039/959] Disable mirage on local --- tests/dummy/config/environment.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index e5c2430e6..a5827a8cd 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -20,7 +20,10 @@ module.exports = function(environment) { 'ember-simple-auth': { authenticationRoute: 'login', routeAfterAuthentication: 'index' - } + }, + 'ember-cli-mirage': { + enabled: false + } }; if (environment === 'development') { From 9408bb273e91e77186291db6d94ea2442c0c6fb9 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 9 May 2016 16:01:31 -0400 Subject: [PATCH 040/959] Simplify serializer logic --- addon/serializers/application.js | 38 +++++++---------------- tests/dummy/app/templates/nodes/index.hbs | 8 ++--- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 5b752e78d..5f185b232 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -2,35 +2,19 @@ import Ember from 'ember'; import DS from 'ember-data'; export default DS.JSONAPISerializer.extend({ - _normalizeAttributes(attributes) { - var normalized = {}; - Object.keys(attributes).forEach(function(key) { - normalized[Ember.String.camelize(key)] = attributes[key]; - }); - return normalized; - }, - _normalizeRecord(record) { - record.attributes = this._normalizeAttributes(record.attributes); - if (record.links) { - record.attributes.links = record.links; + extractAttributes(modelClass, resourceHash) { + //ApiV2 `links` exist outside the attributes field; make them accessible to the data model + if (resourceHash.links) { // TODO: Should also test whether model class defines a links field + resourceHash.attributes.links = resourceHash.links; } - return record; - }, - normalizeSingleResponse(_, __, payload) { - payload.data = this._normalizeRecord(payload.data); - return this._super(...arguments); - }, - normalizeArrayResponse(_, __, payload) { - payload.data = payload.data.map(this._normalizeRecord.bind(this)); - return this._super(...arguments); - }, - keyForAttribute(key) { - return Ember.String.camelize(key); + return this._super(modelClass, resourceHash); }, - serializeIntoHash(/*hash, typeClass, snapshot, options*/) { - // Don't send links as part of hash - // TODO - return this._super(...arguments); + keyForAttribute(key, method) { + if (method === 'deserialize') { + return Ember.String.underscore(key); + } else if (method === 'serialize') { // TOOD: Is this needed? Test serialization + return Ember.String.camelize(key); + } } }); diff --git a/tests/dummy/app/templates/nodes/index.hbs b/tests/dummy/app/templates/nodes/index.hbs index 6234c45dd..4f00c6306 100644 --- a/tests/dummy/app/templates/nodes/index.hbs +++ b/tests/dummy/app/templates/nodes/index.hbs @@ -2,10 +2,10 @@ {{#each model as |node|}}
-

{{node.title}}

-

{{node.category}}

-

{{moment-format node.dateCreated}}

-

{{moment-format node.dateModified}}

+

{{node.title}}

+

{{node.category}}

+

{{moment-format node.dateCreated}}

+

{{moment-format node.dateModified}}

View on OSF From 3ca2ee5f64139261f846cce06c72d0c74970a1e8 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 15:59:27 -0400 Subject: [PATCH 041/959] Remove .env reference from README - change Error to console.log --- README.md | 2 +- index.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0f6fea917..7f8179144 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This repo contains code for interacting with the OSF APIv2 inside of an Ember ap 2. From the consuming Ember app: - install the addon and it's dependencies: `ember install ../ember-osf` - link the app for local development: `npm link ../ember-osf` - - generate a .env (see 'Configuration' below): `ember generate env stage` + - generate a settings file (see 'Configuration' below) - Import code from ember-osf like: ```javascript import Ember from 'ember'; diff --git a/index.js b/index.js index 510388ca9..eee09d54f 100644 --- a/index.js +++ b/index.js @@ -6,10 +6,13 @@ module.exports = { name: 'ember-osf', config: function(environment, ENV) { let BACKEND = process.env.BACKEND || 'local'; - if (!config.has(BACKEND)) { - throw new Error(`WARNING: you have specified a backend: ${BACKEND} that you have not configured in your local.yml`); + let SETTINGS = {}; + try { + SETTINGS = config.get(BACKEND); + } + catch (e) { + console.log(`WARNING: you have specified a backend '${BACKEND}' that you have not configured in your config/.yml`); } - let SETTINGS = config.get(BACKEND); ENV.OSF = { clientId: SETTINGS.CLIENT_ID, From ac26c9944039dbea2301c252e3b2243443bc1566 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 9 May 2016 16:54:57 -0400 Subject: [PATCH 042/959] Semantic heading levels, not stylistic --- tests/dummy/app/templates/application.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index 979afbede..5d6d4df6d 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1,6 +1,6 @@

{{link-to 'Home' 'index' class="btn btn-default"}} -

Welcome to OSF Ember Example App

+

Welcome to OSF Ember Example App

{{outlet}} From f43999c7059da4ff6702cecf872d20c17319a20c Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 22:24:23 -0400 Subject: [PATCH 043/959] Add .github and Contributing guide --- .github/CONTRIBUTING.md | 24 ++++++++++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 9 ++++++++ README.md | 4 ++++ package.json | 5 ++++ tests/dummy/app/styles/{app.css => app.scss} | 0 5 files changed, 42 insertions(+) create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md rename tests/dummy/app/styles/{app.css => app.scss} (100%) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 000000000..42e119309 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,24 @@ +### Naming conventions + +Please review and adhere to the naming conventions defined [here](http://ember-cli.com/user-guide/#naming-conventions) + +### Accessability + +The [ember-a11y](https://www.npmjs.com/package/ember-a11y) addon is a dependency of this addon, and helps facilitate compliance with the guidelines laid out by the [A11y Project](http://a11yproject.com/). This requires one simple change: wherever you would normally use the `{{outlet}}` helper, instead use `{{focusing-outlet}}`. See the project page for more details. + +### Internationalization + +_(In Progress)_ We plan to use the [ember-i18n](https://github.com/jamesarosen/ember-i18n) addon for internationalization support in all components. The main change required here is that all blocks of texrt should be wrapped with the `t` helper supplied by this library. Read more here: [https://github.com/jamesarosen/ember-i18n/wiki/Doc:-Translating-Text](https://github.com/jamesarosen/ember-i18n/wiki/Doc:-Translating-Text) + +### Components + +We will use "pod" style structure for all of the components in this addon. As long as you use the ember-cli to generate the component scaffolds (`ember g component my-component`) , this should happend by default. Basically components should be structured like: + +- addon/components// + - component.js + - template.hbs + - style.scss (optional) + +#### Styling components + +Leveraging the [ember-component-css](https://github.com/ebryn/ember-component-css) addon will allow us to bundle [Sass](http://sass-lang.com/) files inside components' pod structure, and will automatically namespace those styles to avoid all possible CSS collisions. This approach will allow for easy overrides and paramterization via top-level Sass variables. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..31130b2f8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,9 @@ +## Ticket + +# Purpose + +# Notes for Reviewers + +### Routes Added/Updated + + diff --git a/README.md b/README.md index 7f8179144..e3bb8aec0 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ This repo contains code for interacting with the OSF APIv2 inside of an Ember app. +## Contributing? + +Please read the [CONTRIBUTING.md](https://github.com/CenterForOpenScience/ember-osf/blob/develop/.github/CONTRIBUTING.md) + ## Using this code in an Ember app 1. Clone the repository: `git clone https://github.com/CenterForOpenScience/ember-osf.git` diff --git a/package.json b/package.json index 0f2b8b2c3..c77d9c441 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,8 @@ "devDependencies": { "broccoli-asset-rev": "^2.2.0", "config": "^1.20.1", + "ember-a11y": "0.1.8", + "ember-a11y-testing": "0.0.5", "ember-ajax": "0.7.1", "ember-cli": "^2.4.3", "ember-cli-app-version": "^1.0.0", @@ -31,6 +33,7 @@ "ember-cli-moment-shim": "1.1.0", "ember-cli-qunit": "^1.2.1", "ember-cli-release": "0.2.8", + "ember-cli-sass": "5.3.1", "ember-cli-sri": "^2.0.0", "ember-cli-uglify": "^1.2.0", "ember-data": "^2.3.0", @@ -41,6 +44,8 @@ "ember-load-initializers": "0.5.1", "ember-moment": "6.1.0", "ember-resolver": "2.0.3", + "ember-sinon": "0.5.0", + "ember-sinon-qunit": "1.3.1", "js-yaml": "^3.6.0", "loader": "2.1.0", "loader.js": "4.0.3", diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.scss similarity index 100% rename from tests/dummy/app/styles/app.css rename to tests/dummy/app/styles/app.scss From 1f2f5bcded977526ba6092797f57dd1bb8412ed8 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 22:25:21 -0400 Subject: [PATCH 044/959] Update CONTRIBUTING.md --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 42e119309..ddef968b2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -8,7 +8,7 @@ The [ember-a11y](https://www.npmjs.com/package/ember-a11y) addon is a dependency ### Internationalization -_(In Progress)_ We plan to use the [ember-i18n](https://github.com/jamesarosen/ember-i18n) addon for internationalization support in all components. The main change required here is that all blocks of texrt should be wrapped with the `t` helper supplied by this library. Read more here: [https://github.com/jamesarosen/ember-i18n/wiki/Doc:-Translating-Text](https://github.com/jamesarosen/ember-i18n/wiki/Doc:-Translating-Text) +_(In Progress)_ We plan to use the [ember-i18n](https://github.com/jamesarosen/ember-i18n) addon for internationalization support in all components. The main change required here is that all blocks of text should be wrapped with the `t` helper supplied by this library. Read more here: [https://github.com/jamesarosen/ember-i18n/wiki/Doc:-Translating-Text](https://github.com/jamesarosen/ember-i18n/wiki/Doc:-Translating-Text) ### Components From c0e66b6a4807a663dbb9630bcb934519ab4ce41d Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Mon, 9 May 2016 22:37:55 -0400 Subject: [PATCH 045/959] Add testing notes [skip ci] --- .github/CONTRIBUTING.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 42e119309..ee6aaffb1 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,3 +1,5 @@ +# Style/Conventions + ### Naming conventions Please review and adhere to the naming conventions defined [here](http://ember-cli.com/user-guide/#naming-conventions) @@ -22,3 +24,24 @@ We will use "pod" style structure for all of the components in this addon. As lo #### Styling components Leveraging the [ember-component-css](https://github.com/ebryn/ember-component-css) addon will allow us to bundle [Sass](http://sass-lang.com/) files inside components' pod structure, and will automatically namespace those styles to avoid all possible CSS collisions. This approach will allow for easy overrides and paramterization via top-level Sass variables. + +# Testing + + +## Unit tests + +We aim to have near-full test coverage of the code in this addon. That said we want to avoid testing the Ember core or third-party libraries, so some general guidelines for unit tets (minumum requirements): + +**Models** +_Do test_: +- helper methods +- custom transforms + +**Components/Mixins** +_Do test_: +- methods +- computed values + +## Integration tests + +Integration tests allow us to see how components behave while actually running in a browser enviornment. [TODO](https://openscience.atlassian.net/browse/EOSF-28) From 63e95a180bd7a54e762792a9539e7cea178415fe Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 10 May 2016 09:38:35 -0400 Subject: [PATCH 046/959] Only embed contributors on GET requests - also test embed behavior --- addon/adapters/node.js | 10 ++++++++-- addon/mixins/osf-login-route.js | 2 +- index.js | 2 +- tests/unit/adapters/node-test.js | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 6e925e874..de4904b86 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -1,8 +1,14 @@ import ApplicationAdapter from './application'; export default ApplicationAdapter.extend({ - buildURL() { + buildURL(_, __, ___, requestType) { // Embed contributors - return `${this._super(...arguments)}?embed=contributors`; + var base = this._super(...arguments); + if (requestType === 'GET') { + return `${base}?embed=contributors`; + } + else { + return base; + } } }); diff --git a/addon/mixins/osf-login-route.js b/addon/mixins/osf-login-route.js index ba1d3bc12..6fed1cd3f 100644 --- a/addon/mixins/osf-login-route.js +++ b/addon/mixins/osf-login-route.js @@ -7,7 +7,7 @@ export default Ember.Mixin.create(UnauthenticatedRouteMixin, { session: Ember.inject.service(), beforeModel() { var accessToken; - if (config.OSF.local) { + if (config.OSF.isLocal) { accessToken = config.OSF.accessToken; } else { // Acquire an OSF access token, then exchange it for a Jam token diff --git a/index.js b/index.js index eee09d54f..25e72de8e 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ module.exports = { ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; - ENV.OSF.local = true; + ENV.OSF.isLocal = true; } if (BACKEND === 'stage') { ENV.OSF.url = 'https://staging.osf.io/'; diff --git a/tests/unit/adapters/node-test.js b/tests/unit/adapters/node-test.js index abea40157..b7a3e06b9 100644 --- a/tests/unit/adapters/node-test.js +++ b/tests/unit/adapters/node-test.js @@ -8,6 +8,6 @@ moduleFor('adapter:node', 'Unit | Adapter | node', { test('it embeds contributors', function(assert) { let adapter = this.subject(); - //let url = adapter.buildURL('nodes', null, null, 'GET', null); - assert.ok(adapter); + let url = adapter.buildURL('nodes', null, null, 'GET', null); + assert.ok(url.indexOf('embed=contributors')); }); From e6bc06d08cf50cad8691d59a50b5ef416d9fa814 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 10 May 2016 10:19:29 -0400 Subject: [PATCH 047/959] Simplify URL logic and always append trailing slash (to0 avoid redirects on preflighting; DRF seems to insist on trialing slash) --- addon/adapters/application.js | 13 ++++++++----- index.js | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/addon/adapters/application.js b/addon/adapters/application.js index 9f4b34755..4e26d40ae 100644 --- a/addon/adapters/application.js +++ b/addon/adapters/application.js @@ -8,11 +8,14 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { authorizer: 'authorizer:osf-token', host: config.OSF.apiUrl, + namespace: config.OSF.apiNamespace, pathForType: Ember.String.pluralize, - urlForFindRecord (id, modelName/*, snapshot*/) { - return `${this.get('host')}${Ember.String.pluralize(modelName)}/${id}/`; - }, - urlForFindAll (modelName) { - return `${this.get('host')}${Ember.String.pluralize(modelName)}/`; + + buildURL() { + var url = this._super(...arguments); + if (!url.endsWith('/')) { + url += '/'; + } + return url; } }); diff --git a/index.js b/index.js index efab97a95..d88f8bf6d 100644 --- a/index.js +++ b/index.js @@ -17,30 +17,30 @@ module.exports = { ENV.OSF = { clientId: process.env.OSF_CLIENT_ID, - scope: process.env.OSF_SCOPE + scope: process.env.OSF_SCOPE, + apiNamespace: 'v2' // URL suffix (after host) }; - if (environment === 'development') { - ENV.OSF.url = 'http://localhost:5000/'; - ENV.OSF.apiUrl = 'http://localhost:8000/v2/'; + ENV.OSF.url = 'http://localhost:5000'; + ENV.OSF.apiUrl = 'http://localhost:8000'; ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; ENV.OSF.accessToken = process.env.OSF_ACCESS_TOKEN; ENV.DEV = true; } if (environment === 'staging') { - ENV.OSF.url = 'https://staging.osf.io/'; - ENV.OSF.apiUrl = 'https://staging-api.osf.io/v2/'; + ENV.OSF.url = 'https://staging.osf.io'; + ENV.OSF.apiUrl = 'https://staging-api.osf.io'; ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; } if (environment === 'staging2') { - ENV.OSF.url = 'https://staging2.osf.io/'; - ENV.OSF.apiUrl = 'https://staging2-api.osf.io/v2/'; + ENV.OSF.url = 'https://staging2.osf.io'; + ENV.OSF.apiUrl = 'https://staging2-api.osf.io'; ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; } if (environment === 'production') { - ENV.OSF.url = 'https://osf.io/'; - ENV.OSF.apiUrl = 'https://api.osf.io/v2/'; + ENV.OSF.url = 'https://osf.io'; + ENV.OSF.apiUrl = 'https://api.osf.io'; ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; } From 872348f68f7ee7296d3827601cf581375c0e3139 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 10 May 2016 10:23:52 -0400 Subject: [PATCH 048/959] Add en-us locale --- app/locales/en-us/config.js | 16 ++++++++++++++++ app/locales/en-us/translations.js | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 app/locales/en-us/config.js create mode 100644 app/locales/en-us/translations.js diff --git a/app/locales/en-us/config.js b/app/locales/en-us/config.js new file mode 100644 index 000000000..42b3d17a5 --- /dev/null +++ b/app/locales/en-us/config.js @@ -0,0 +1,16 @@ +// Ember-I18n includes configuration for common locales. Most users +// can safely delete this file. Use it if you need to override behavior +// for a locale or define behavior for a locale that Ember-I18n +// doesn't know about. +export default { + // rtl: [true|FALSE], + // + // pluralForm: function(count) { + // if (count === 0) { return 'zero'; } + // if (count === 1) { return 'one'; } + // if (count === 2) { return 'two'; } + // if (count < 5) { return 'few'; } + // if (count >= 5) { return 'many'; } + // return 'other'; + // } +}; diff --git a/app/locales/en-us/translations.js b/app/locales/en-us/translations.js new file mode 100644 index 000000000..331fb469a --- /dev/null +++ b/app/locales/en-us/translations.js @@ -0,0 +1,11 @@ +export default { + // "some.translation.key": "Text for some.translation.key", + // + // "a": { + // "nested": { + // "key": "Text for a.nested.key" + // } + // }, + // + // "key.with.interpolation": "Text with {{anInterpolation}}" +}; From 421bf129e90d467ae4638d39e6265b3a5c465032 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 10 May 2016 10:50:34 -0400 Subject: [PATCH 049/959] Don't pod by default - This forces routes to use pod structuring as well, which is not ideal --- .ember-cli | 3 +-- .github/CONTRIBUTING.md | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.ember-cli b/.ember-cli index e0e1c5ce1..ee64cfed2 100644 --- a/.ember-cli +++ b/.ember-cli @@ -5,6 +5,5 @@ Setting `disableAnalytics` to true will prevent any data from being sent. */ - "disableAnalytics": false, - "pod": true + "disableAnalytics": false } diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 6ed3b9ed7..6dc8d3a9b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -14,7 +14,7 @@ _(In Progress)_ We plan to use the [ember-i18n](https://github.com/jamesarosen/e ### Components -We will use "pod" style structure for all of the components in this addon. As long as you use the ember-cli to generate the component scaffolds (`ember g component my-component`) , this should happend by default. Basically components should be structured like: +We will use "pod" style structure for all of the components in this addon. This means when generating component scaffolds with ember-cli you must pass the --pod flag: `ember g component my-component --pod`. Basically components should be structured like: - addon/components// - component.js From f0f02afe870bbcdfafd0aacb1d409956dcc9a388 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 10 May 2016 10:52:13 -0400 Subject: [PATCH 050/959] Misc cleanup --- addon/adapters/node.js | 1 + addon/authenticators/osf-token.js | 2 +- addon/models/node.js | 2 +- tests/dummy/app/router.js | 2 +- tests/dummy/app/routes/nodes.js | 9 +++++++++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 5ce0d304d..bb3b9a8fa 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -3,6 +3,7 @@ import ApplicationAdapter from './application'; export default ApplicationAdapter.extend({ buildURL() { // Embed contributors + // TODO: We only want to add the embed parameter on GET requests (not POST) return `${this._super(...arguments)}?embed=contributors`; } }); diff --git a/addon/authenticators/osf-token.js b/addon/authenticators/osf-token.js index 470c8730d..9727ff8a4 100644 --- a/addon/authenticators/osf-token.js +++ b/addon/authenticators/osf-token.js @@ -9,7 +9,7 @@ export default BaseAuthenticator.extend({ _test (accessToken) { return Ember.$.ajax({ method: 'GET', - url: `${config.OSF.apiUrl}users/me/`, + url: `${config.OSF.apiUrl}/${config.OSF.apiNamespace}/users/me/`, dataType: 'json', contentType: 'application/json', xhrFields: {withCredentials: false}, diff --git a/addon/models/node.js b/addon/models/node.js index 069c2313b..25e5fbd3b 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -34,7 +34,7 @@ export default OsfModel.extend({ //forkedFrom: DS.belongsTo('node'), //nodeLinks: DS.hasMany('node-pointers'), //registrations: DS.hasMany('registrations'), - //primaryInistution: DS.belongsTo('institution'), + //primaryInstitution: DS.belongsTo('institution'), root: DS.belongsTo('node') //logs: DS.hasMany('node-logs'), }); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index db980d984..dc7d751eb 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -8,7 +8,7 @@ const Router = Ember.Router.extend({ Router.map(function() { this.route('index', {path: '/'}); this.route('nodes', function() { - this.route('detail', {path: '/:node_id'}); + this.route('detail', {path: '/:node_id'}); }); this.route('login'); }); diff --git a/tests/dummy/app/routes/nodes.js b/tests/dummy/app/routes/nodes.js index 4d5032adf..4ef33ccd9 100644 --- a/tests/dummy/app/routes/nodes.js +++ b/tests/dummy/app/routes/nodes.js @@ -7,5 +7,14 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { model() { const user = this.modelFor('application'); return user.get('nodes'); // Fetch from `/users/me/nodes/` + }, + + actions: { + createNew() { + // TODO: Just hardcode a payload here, tests POST + console.log('button was clicked'); + //var record = this.store.createRecord('node', {}); // TODO write + //record.save(); + } } }); From ca7bef22cba74762c0b1691ec564201f059e8020 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 10 May 2016 11:56:29 -0400 Subject: [PATCH 051/959] Add wip code to create/edit (test server writes) --- addon/serializers/application.js | 10 +++++- tests/dummy/app/routes/nodes/detail.js | 20 +++++++++++ tests/dummy/app/templates/nodes/detail.hbs | 40 ++++++++++++++-------- tests/dummy/app/templates/nodes/index.hbs | 4 +++ 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 5f185b232..97829761e 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -3,7 +3,7 @@ import DS from 'ember-data'; export default DS.JSONAPISerializer.extend({ extractAttributes(modelClass, resourceHash) { - //ApiV2 `links` exist outside the attributes field; make them accessible to the data model + // ApiV2 `links` exist outside the attributes field; make them accessible to the data model if (resourceHash.links) { // TODO: Should also test whether model class defines a links field resourceHash.attributes.links = resourceHash.links; } @@ -17,4 +17,12 @@ export default DS.JSONAPISerializer.extend({ return Ember.String.camelize(key); } } + + + // TODO: Sending back to server requires + // 1. Remove links from payload (try something like serializer attrs: field{serialize:false}), and what happens if record has no links field? + // 2. Rename keys in payload (try setting something with snake case) + // 3. Veirfy post, put, and patch operations + // 4. Don't send relationships, if that breaks writing operations + }); diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index ccd983323..a90314bff 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -3,5 +3,25 @@ import Ember from 'ember'; export default Ember.Route.extend({ model(params) { return this.store.findRecord('node', params.node_id); + }, + + setupController(controller, model) { + controller.set('editedTitle', model.get('title')); + this._super(...arguments); + }, + + actions: { + editExisting(value) { + // TODO: Should test PUT or PATCH + console.log('Will edit title from', this.modelFor(this.routeName).get('title'), ' to ', value); + var node = this.modelFor(this.routeName); + if (node.get('currentUserPermissions').indexOf('write') !== -1) { + node.set('title', value); + node.save(); + } else { + console.log('You do not have permissions to edit this node'); + } + } } + }); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 914145e0f..05bba69c0 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -1,26 +1,38 @@ {{link-to 'Back to list' 'nodes' class="btn btn-default"}}
-

{{model.title}}

-

{{model.category}}

-

{{moment-format model.dateCreated}}

-

{{moment-format model.dateModified}}

+ +

Data

+

{{model.title}}

+

{{model.category}}

+

{{moment-format model.dateCreated}}

+

{{moment-format model.dateModified}}

View on OSF


-

- -

+ +

Contributors

+ - {{#each model.contributors as |contrib|}} - - {{contrib.bibliographic}} - - {{/each}} + + + + + {{#each model.contributors as |contrib|}} + + + + + {{/each}}
IDAuthor?
{{contrib.id}}{{contrib.bibliographic}}
-

-

+ + + +

Edit this node

+ Title: {{input value=editedTitle}} + +
diff --git a/tests/dummy/app/templates/nodes/index.hbs b/tests/dummy/app/templates/nodes/index.hbs index 4f00c6306..3926175a0 100644 --- a/tests/dummy/app/templates/nodes/index.hbs +++ b/tests/dummy/app/templates/nodes/index.hbs @@ -1,4 +1,8 @@

My Nodes

+ + + + {{#each model as |node|}}
From 054026e322242c2c5fcce26495939c1072d21ea0 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 10 May 2016 12:12:34 -0400 Subject: [PATCH 052/959] Some package.json reorganizing - some modules must be regular dependencies to get installed by consuming apps - also add uri-template.js import --- index.js | 9 +++++++++ package.json | 16 ++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 25e72de8e..f6aaf9f38 100644 --- a/index.js +++ b/index.js @@ -46,5 +46,14 @@ module.exports = { ENV['ember-simple-auth'] = { authorizer: 'authorizer:osf-token' }; + }, + // A small hack for ember-data-url-templates to work + // TODO: followup based on https://github.com/dfreeman/ember-cli-node-assets/issues/1 + options: { + nodeAssets: { + 'uri-templates': { + import: ['uri-templates.js'] + } + } } }; diff --git a/package.json b/package.json index c77d9c441..158f93502 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "license": "MIT", "devDependencies": { "broccoli-asset-rev": "^2.2.0", - "config": "^1.20.1", "ember-a11y": "0.1.8", "ember-a11y-testing": "0.0.5", "ember-ajax": "0.7.1", @@ -30,23 +29,20 @@ "ember-cli-htmlbars-inline-precompile": "^0.3.1", "ember-cli-inject-live-reload": "^1.3.1", "ember-cli-mirage": "0.1.13", - "ember-cli-moment-shim": "1.1.0", "ember-cli-qunit": "^1.2.1", "ember-cli-release": "0.2.8", "ember-cli-sass": "5.3.1", "ember-cli-sri": "^2.0.0", "ember-cli-uglify": "^1.2.0", "ember-data": "^2.3.0", - "ember-data-url-templates": "0.1.1", "ember-disable-prototype-extensions": "^1.0.0", "ember-disable-proxy-controllers": "^1.0.1", "ember-export-application-global": "^1.0.4", + "ember-i18n": "4.2.1", "ember-load-initializers": "0.5.1", - "ember-moment": "6.1.0", "ember-resolver": "2.0.3", "ember-sinon": "0.5.0", "ember-sinon-qunit": "1.3.1", - "js-yaml": "^3.6.0", "loader": "2.1.0", "loader.js": "4.0.3", "moment": "^2.13.0" @@ -55,12 +51,16 @@ "ember-addon" ], "dependencies": { + "config": "^1.20.1", "ember-cli-babel": "^5.1.5", - "loader": "^2.1.0", - "ember-simple-auth": "1.1.0-beta.5", + "ember-cli-moment-shim": "1.1.0", + "ember-cli-node-assets": "^0.1.3", + "ember-data-url-templates": "^0.1.1", "ember-get-config": "0.0.2", "ember-moment": "6.1.0", - "dotenv": "^2.0.0" + "ember-simple-auth": "1.1.0-beta.5", + "js-yaml": "^3.6.0", + "uri-templates": "^0.1.9" }, "ember-addon": { "configPath": "tests/dummy/config" From 377d0d02f79f2cf5f22c40e14a2fa621eb3a6f09 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 10 May 2016 12:16:12 -0400 Subject: [PATCH 053/959] Add ember-a11y-testing notes --- .github/CONTRIBUTING.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 6dc8d3a9b..eff1ff826 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -45,3 +45,8 @@ _Do test_: ## Integration tests Integration tests allow us to see how components behave while actually running in a browser enviornment. [TODO](https://openscience.atlassian.net/browse/EOSF-28) + +#### Accessability checks + +We will use the [ember-a11y-testing](https://github.com/trentmwillis/ember-a11y-testing) addon to run a11y checks on all components. + From 6e149d2ec171fb05e48759dbc1fbea709a1141bf Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 10 May 2016 12:23:39 -0400 Subject: [PATCH 054/959] Only embed contributors on non-C.U.D. requests --- addon/adapters/node.js | 2 +- tests/unit/adapters/node-test.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index de4904b86..a68261fd3 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -4,7 +4,7 @@ export default ApplicationAdapter.extend({ buildURL(_, __, ___, requestType) { // Embed contributors var base = this._super(...arguments); - if (requestType === 'GET') { + if (['createRecord', 'updateRecord', 'deleteRecord'].indexOf(requestType) === -1) { return `${base}?embed=contributors`; } else { diff --git a/tests/unit/adapters/node-test.js b/tests/unit/adapters/node-test.js index b7a3e06b9..8d73c8a06 100644 --- a/tests/unit/adapters/node-test.js +++ b/tests/unit/adapters/node-test.js @@ -5,9 +5,17 @@ moduleFor('adapter:node', 'Unit | Adapter | node', { needs: ['model:node'] }); -test('it embeds contributors', function(assert) { +test('it embeds contributors on non C.U.D. methods', function(assert) { let adapter = this.subject(); - let url = adapter.buildURL('nodes', null, null, 'GET', null); + let url = adapter.buildURL('nodes', null, null, 'findRecord', null); assert.ok(url.indexOf('embed=contributors')); }); +test('it doesn\'t try to embed contributors on C.U.D. methods', function(assert) { + let adapter = this.subject(); + + ['create', 'update', 'delete'].forEach((verb) => { + let url = adapter.buildURL('nodes', null, null, `${verb}Record`, null); + assert.equal(url.indexOf('embed=contributors'), -1); + }); +}); From 5df75637839cb5e31f67c64f58adb56c42a0349c Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 10 May 2016 12:23:39 -0400 Subject: [PATCH 055/959] Only embed contributors on non-C.U.D. requests --- addon/adapters/node.js | 15 +++++++-------- tests/unit/adapters/node-test.js | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index de4904b86..3185c8376 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -2,13 +2,12 @@ import ApplicationAdapter from './application'; export default ApplicationAdapter.extend({ buildURL(_, __, ___, requestType) { - // Embed contributors - var base = this._super(...arguments); - if (requestType === 'GET') { - return `${base}?embed=contributors`; - } - else { - return base; - } + // Embed contributors + var base = this._super(...arguments); + if (['createRecord', 'updateRecord', 'deleteRecord'].indexOf(requestType) === -1) { + return `${base}?embed=contributors`; + } else { + return base; + } } }); diff --git a/tests/unit/adapters/node-test.js b/tests/unit/adapters/node-test.js index b7a3e06b9..51b6cde52 100644 --- a/tests/unit/adapters/node-test.js +++ b/tests/unit/adapters/node-test.js @@ -1,13 +1,24 @@ -import { moduleFor, test } from 'ember-qunit'; +import { + moduleFor, + test +} from 'ember-qunit'; moduleFor('adapter:node', 'Unit | Adapter | node', { - // Specify the other units that are required for this test. + // Specify the other units that are required for this test. needs: ['model:node'] }); -test('it embeds contributors', function(assert) { +test('it embeds contributors on non C.U.D. methods', function(assert) { let adapter = this.subject(); - let url = adapter.buildURL('nodes', null, null, 'GET', null); + let url = adapter.buildURL('nodes', null, null, 'findRecord', null); assert.ok(url.indexOf('embed=contributors')); }); +test('it doesn\'t try to embed contributors on C.U.D. methods', function(assert) { + let adapter = this.subject(); + + ['create', 'update', 'delete'].forEach((verb) => { + let url = adapter.buildURL('nodes', null, null, `${verb}Record`, null); + assert.equal(url.indexOf('embed=contributors'), -1); + }); +}); From 07e54677ef8f1f3353c223c43d13b40fad941ff9 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 10 May 2016 13:33:30 -0400 Subject: [PATCH 056/959] Fix merge goofs --- addon/serializers/application.js | 4 ++-- index.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 0ed9640de..7a0927e58 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -9,7 +9,7 @@ export default DS.JSONAPISerializer.extend({ } if (resourceHash.embeds) { // TODO, actually merge in embedded data? - resourceHash.attributes.embeds = record.embeds; + resourceHash.attributes.embeds = resourceHash.embeds; } return this._super(modelClass, resourceHash); }, @@ -21,7 +21,7 @@ export default DS.JSONAPISerializer.extend({ return Ember.String.camelize(key); } } - + // TODO: Sending back to server requires // 1. Remove links from payload (try something like serializer attrs: field{serialize:false}), and what happens if record has no links field? // 2. Rename keys in payload (try setting something with snake case) diff --git a/index.js b/index.js index 83c840c9f..5307478f1 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ module.exports = { if (BACKEND === 'local') { ENV.OSF.url = 'http://localhost:5000/'; - ENV.OSF.apiUrl = 'http://localhost:8000/v2/'; + ENV.OSF.apiUrl = 'http://localhost:8000'; ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; @@ -46,6 +46,6 @@ module.exports = { ENV['ember-simple-auth'] = { authorizer: 'authorizer:osf-token' - }; + }; } }; From b631dfe7a57c96612e020541caed18ee3f394efc Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 10 May 2016 14:03:56 -0400 Subject: [PATCH 057/959] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e3bb8aec0..3caa17b90 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ to fetch all nodes. ## Configuration -#### Using the Staging or Production API (preferred) +#### Using the Staging or Test API To do this, you will need to [create a developer application](https://staging.osf.io/settings/applications/) on the relevant version of the OSF. From 6c6fb336b907a7c30f721a24e8856d780b99f2b8 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 10 May 2016 14:06:36 -0400 Subject: [PATCH 058/959] More style cleanup --- addon/adapters/application.js | 1 + index.js | 74 ++++++++++++++++----------------- tests/dummy/app/routes/nodes.js | 2 +- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/addon/adapters/application.js b/addon/adapters/application.js index 657314ce7..3a80a17ea 100644 --- a/addon/adapters/application.js +++ b/addon/adapters/application.js @@ -12,6 +12,7 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { buildURL() { var url = this._super(...arguments); + // TODO: Is this still necessary? if (!url.endsWith('/')) { url += '/'; } diff --git a/index.js b/index.js index 5307478f1..4af250e3c 100644 --- a/index.js +++ b/index.js @@ -5,47 +5,47 @@ var config = require('config'); module.exports = { name: 'ember-osf', config: function(environment, ENV) { - let BACKEND = process.env.BACKEND || 'local'; - let SETTINGS = {}; - try { - SETTINGS = config.get(BACKEND); - } - catch (e) { - console.log(`WARNING: you have specified a backend '${BACKEND}' that you have not configured in your config/.yml`); - } + let BACKEND = process.env.BACKEND || 'local'; + let SETTINGS = {}; + try { + SETTINGS = config.get(BACKEND); + } + catch (e) { + console.log(`WARNING: you have specified a backend '${BACKEND}' that you have not configured in your config/.yml`); + } - ENV.OSF = { - clientId: SETTINGS.CLIENT_ID, - scope: SETTINGS.OAUTH_SCOPES, - apiNamespace: 'v2' // URL suffix (after host) + ENV.OSF = { + clientId: SETTINGS.CLIENT_ID, + scope: SETTINGS.OAUTH_SCOPES, + apiNamespace: 'v2' // URL suffix (after host) }; - if (BACKEND === 'local') { - ENV.OSF.url = 'http://localhost:5000/'; - ENV.OSF.apiUrl = 'http://localhost:8000'; - ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; + if (BACKEND === 'local') { + ENV.OSF.url = 'http://localhost:5000/'; + ENV.OSF.apiUrl = 'http://localhost:8000'; + ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; - ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; - ENV.OSF.local = true; - } - if (BACKEND === 'stage') { - ENV.OSF.url = 'https://staging.osf.io/'; - ENV.OSF.apiUrl = 'https://staging-api.osf.io'; - ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; - } - if (BACKEND === 'stage2') { - ENV.OSF.url = 'https://staging2.osf.io/'; - ENV.OSF.apiUrl = 'https://staging2-api.osf.io'; - ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; - } - if (BACKEND === 'prod') { - ENV.OSF.url = 'https://osf.io/'; - ENV.OSF.apiUrl = 'https://api.osf.io'; - ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; - } + ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; + ENV.OSF.local = true; + } + if (BACKEND === 'stage') { + ENV.OSF.url = 'https://staging.osf.io/'; + ENV.OSF.apiUrl = 'https://staging-api.osf.io'; + ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; + } + if (BACKEND === 'stage2') { + ENV.OSF.url = 'https://staging2.osf.io/'; + ENV.OSF.apiUrl = 'https://staging2-api.osf.io'; + ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; + } + if (BACKEND === 'prod') { + ENV.OSF.url = 'https://osf.io/'; + ENV.OSF.apiUrl = 'https://api.osf.io'; + ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; + } - ENV['ember-simple-auth'] = { - authorizer: 'authorizer:osf-token' - }; + ENV['ember-simple-auth'] = { + authorizer: 'authorizer:osf-token' + }; } }; diff --git a/tests/dummy/app/routes/nodes.js b/tests/dummy/app/routes/nodes.js index 058cb1a75..0a3f1c5ef 100644 --- a/tests/dummy/app/routes/nodes.js +++ b/tests/dummy/app/routes/nodes.js @@ -10,7 +10,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { return user.get('nodes'); // Fetch from `/users/me/nodes/` } else { - return this.get('store').findRecord('user', 'me').then (user => user.get('nodes')); + return this.get('store').findRecord('user', 'me').then(user => user.get('nodes')); } }, actions: { From c4882dc4cd848f1dd9fc5f96286def02bee1635c Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 10 May 2016 17:22:42 -0400 Subject: [PATCH 059/959] Exclude links, embeds, and relationships from payload --- addon/mixins/osf-login-route.js | 3 ++- addon/serializers/application.js | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/addon/mixins/osf-login-route.js b/addon/mixins/osf-login-route.js index 6fed1cd3f..f8ed29827 100644 --- a/addon/mixins/osf-login-route.js +++ b/addon/mixins/osf-login-route.js @@ -10,8 +10,9 @@ export default Ember.Mixin.create(UnauthenticatedRouteMixin, { if (config.OSF.isLocal) { accessToken = config.OSF.accessToken; } else { - // Acquire an OSF access token, then exchange it for a Jam token + // Acquire an OSF access token, then exchange it for a Jam token // TODO: Jam? var hash = window.location.hash.substring(1).split('&').map(function(str) { + // TODO: Comma expression; check with Sam on intent return this[str.split('=')[0]] = str.split('=')[1], this; }.bind({}))[0]; if (!hash || !hash.access_token) { diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 7a0927e58..9358bd6c9 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -2,13 +2,17 @@ import Ember from 'ember'; import DS from 'ember-data'; export default DS.JSONAPISerializer.extend({ + attrs: { + links: {serialize: false}, + embeds: {serialize: false} + }, + extractAttributes(modelClass, resourceHash) { // ApiV2 `links` exist outside the attributes field; make them accessible to the data model if (resourceHash.links) { // TODO: Should also test whether model class defines a links field resourceHash.attributes.links = resourceHash.links; } if (resourceHash.embeds) { - // TODO, actually merge in embedded data? resourceHash.attributes.embeds = resourceHash.embeds; } return this._super(modelClass, resourceHash); @@ -17,15 +21,15 @@ export default DS.JSONAPISerializer.extend({ keyForAttribute(key, method) { if (method === 'deserialize') { return Ember.String.underscore(key); - } else if (method === 'serialize') { // TOOD: Is this needed? Test serialization + } else if (method === 'serialize') { return Ember.String.camelize(key); } - } - - // TODO: Sending back to server requires - // 1. Remove links from payload (try something like serializer attrs: field{serialize:false}), and what happens if record has no links field? - // 2. Rename keys in payload (try setting something with snake case) - // 3. Veirfy post, put, and patch operations - // 4. Don't send relationships, if that breaks writing operations + }, + serialize: function(snapshot, options) { + var serialized = this._super(snapshot, options); + // Don't send relationships to the server; this can lead to 500 errors. + delete serialized.data.relationships; + return serialized; + } }); From 6b3d6f49fe95c0e817dea87b1bdf174eb92e5f4c Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 10 May 2016 17:30:07 -0400 Subject: [PATCH 060/959] Remove two unused dependencies --- addon/serializers/application.js | 2 ++ package.json | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 9358bd6c9..bed8dbf8c 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -2,6 +2,8 @@ import Ember from 'ember'; import DS from 'ember-data'; export default DS.JSONAPISerializer.extend({ + + // TODO: Pre-1.0, refactor this into a separate OSF serializer, so we can support other microservices such as WB attrs: { links: {serialize: false}, embeds: {serialize: false} diff --git a/package.json b/package.json index 158f93502..07ab56a32 100644 --- a/package.json +++ b/package.json @@ -55,12 +55,10 @@ "ember-cli-babel": "^5.1.5", "ember-cli-moment-shim": "1.1.0", "ember-cli-node-assets": "^0.1.3", - "ember-data-url-templates": "^0.1.1", "ember-get-config": "0.0.2", "ember-moment": "6.1.0", "ember-simple-auth": "1.1.0-beta.5", - "js-yaml": "^3.6.0", - "uri-templates": "^0.1.9" + "js-yaml": "^3.6.0" }, "ember-addon": { "configPath": "tests/dummy/config" From 86dff602c26997862e1716660feca51519691339 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 10 May 2016 19:09:44 -0400 Subject: [PATCH 061/959] Fix broken tests I'd like a better way to unit test the extractAttributes behavior than splitting into a separate method; suggestions very welcome --- addon/adapters/application.js | 4 +- addon/serializers/application.js | 7 +++- tests/unit/serializers/application-test.js | 45 ++++++++++------------ 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/addon/adapters/application.js b/addon/adapters/application.js index 3a80a17ea..95a3a8b8f 100644 --- a/addon/adapters/application.js +++ b/addon/adapters/application.js @@ -10,10 +10,10 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { namespace: config.OSF.apiNamespace, pathForType: Ember.String.pluralize, - buildURL() { + buildURL(modelName, id, snapshot, requestType, query) { // jshint ignore:line var url = this._super(...arguments); // TODO: Is this still necessary? - if (!url.endsWith('/')) { + if (url.lastIndexOf('/') !== 0) { url += '/'; } return url; diff --git a/addon/serializers/application.js b/addon/serializers/application.js index bed8dbf8c..89ab966f3 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -9,7 +9,7 @@ export default DS.JSONAPISerializer.extend({ embeds: {serialize: false} }, - extractAttributes(modelClass, resourceHash) { + _mergeFields(resourceHash) { // ApiV2 `links` exist outside the attributes field; make them accessible to the data model if (resourceHash.links) { // TODO: Should also test whether model class defines a links field resourceHash.attributes.links = resourceHash.links; @@ -17,6 +17,11 @@ export default DS.JSONAPISerializer.extend({ if (resourceHash.embeds) { resourceHash.attributes.embeds = resourceHash.embeds; } + return resourceHash; + }, + + extractAttributes(modelClass, resourceHash) { + resourceHash = this._mergeFields(resourceHash); return this._super(modelClass, resourceHash); }, diff --git a/tests/unit/serializers/application-test.js b/tests/unit/serializers/application-test.js index ae5fc74a9..77ab6a77c 100644 --- a/tests/unit/serializers/application-test.js +++ b/tests/unit/serializers/application-test.js @@ -5,38 +5,35 @@ moduleForModel('base', 'Unit | Serializer | application', { needs: ['serializer:application'] }); -test('#_normalizeRecord adds links to attributes if included in payload', function(assert) { +test('#_mergeFields adds links to attributes if included in payload', function(assert) { let payload = { - id: faker.random.uuid(), - type: 'base', - attributes: { - key: 'value' - }, - links: { - html: faker.internet.url() - } + id: faker.random.uuid(), + type: 'base', + attributes: { + key: 'value' + }, + links: { + html: faker.internet.url() + } }; - let serializer = this.container.lookup('serializer:application'); - let normalized = serializer._normalizeRecord(payload); - + let normalized = serializer._mergeFields(payload); assert.equal(normalized.attributes.links, payload.links); }); -test('#_normalizeRecord adds links to attributes if included in payload', function(assert) { +test('#_mergeFields adds embeds to attributes if included in payload', function(assert) { let payload = { - id: faker.random.uuid(), - attributes: { - key: 'value' - }, - embeds: { - embedded: { - data: [faker.random.arrayElement()] - } - } + id: faker.random.uuid(), + attributes: { + key: 'value' + }, + embeds: { + embedded: { + data: [faker.random.arrayElement()] + } + } }; - let serializer = this.container.lookup('serializer:application'); - let normalized = serializer._normalizeRecord(payload); + let normalized = serializer._mergeFields(payload); assert.equal(normalized.attributes.embeds, payload.embeds); }); From dc60e1f37a63cd5411d86006c2ed6b5c189e9aa1 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 10 May 2016 19:16:38 -0400 Subject: [PATCH 062/959] Clean up todo --- addon/adapters/application.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addon/adapters/application.js b/addon/adapters/application.js index 95a3a8b8f..cff7dd94b 100644 --- a/addon/adapters/application.js +++ b/addon/adapters/application.js @@ -12,7 +12,8 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { buildURL(modelName, id, snapshot, requestType, query) { // jshint ignore:line var url = this._super(...arguments); - // TODO: Is this still necessary? + // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing + // slash to URLs for single documents, but DRF redirects to force a trailing slash if (url.lastIndexOf('/') !== 0) { url += '/'; } From 5e3c7bcb5fbab55f80f59dec17db0f3d5d249491 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 08:13:54 -0400 Subject: [PATCH 063/959] WIP demonstrating merging embeds Looking at the ember-data source, it seems the JSONAPI serializer expects _either_ relationships links or actual data. We can very possibly borrow this machinery to merge the v2's concept of embeds into the loaded data. --- addon/models/contributor.js | 2 +- addon/models/user.js | 7 ++++--- addon/serializers/application.js | 10 ++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/addon/models/contributor.js b/addon/models/contributor.js index 43a6fe84c..8fc4f6f23 100644 --- a/addon/models/contributor.js +++ b/addon/models/contributor.js @@ -5,5 +5,5 @@ import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ bibliographic: DS.attr('boolean'), permission: DS.attr('string'), - users: DS.hasMany('user') + user: DS.belongsTo('user') }); diff --git a/addon/models/user.js b/addon/models/user.js index 0076a5c79..ca4afab7d 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -3,9 +3,10 @@ import DS from 'ember-data'; import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ - given_name: DS.attr('string'), - middle_names: DS.attr(), - family_name: DS.attr('string'), + givenName: DS.attr('string'), + middleNames: DS.attr(), + familyName: DS.attr('string'), + fullName: DS.attr('string'), nodes: DS.hasMany('nodes') }); diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 89ab966f3..cf64fa66c 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -15,8 +15,13 @@ export default DS.JSONAPISerializer.extend({ resourceHash.attributes.links = resourceHash.links; } if (resourceHash.embeds) { - resourceHash.attributes.embeds = resourceHash.embeds; - } + resourceHash.relationships = resourceHash.relationships || {}; + Object.keys(resourceHash.embeds).forEach(embedded => { + resourceHash.relationships[embedded] = resourceHash.relationships[embedded] || {}; + resourceHash.embeds[embedded].type = embedded; + resourceHash.relationships[embedded] = resourceHash.embeds[embedded]; + }); + } return resourceHash; }, @@ -31,6 +36,7 @@ export default DS.JSONAPISerializer.extend({ } else if (method === 'serialize') { return Ember.String.camelize(key); } + return key; }, serialize: function(snapshot, options) { From 6076893c52a5245d91776a4db479508f63adee1f Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Wed, 11 May 2016 11:03:43 -0400 Subject: [PATCH 064/959] Move all embedded resources into includes --- addon/serializers/application.js | 46 ++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/addon/serializers/application.js b/addon/serializers/application.js index cf64fa66c..b0dd17aee 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -2,29 +2,53 @@ import Ember from 'ember'; import DS from 'ember-data'; export default DS.JSONAPISerializer.extend({ - + // TODO: Pre-1.0, refactor this into a separate OSF serializer, so we can support other microservices such as WB attrs: { links: {serialize: false}, embeds: {serialize: false} }, + _extractEmbeds(resourceHash) { + if (!resourceHash.embeds) { + return []; // Nothing to do + } + let included = []; + resourceHash.relationships = resourceHash.relationships || {}; + for (let embedded in resourceHash.embeds) { + if (!(embedded || resourceHash.embeds[embedded])) { + continue; + } + //TODO Pagination probably breaks here + let data = resourceHash.embeds[embedded].data; + if (Array.isArray(data)) { + included = included.concat(data); + } else { + included.push(data); + } + resourceHash.embeds[embedded].type = embedded; + //Only needs to contain id and type but this way we don't have to special case arrays + resourceHash.relationships[embedded] = resourceHash.embeds[embedded]; + } + delete resourceHash.embeds; + //Recurse in, includeds are only processed on the top level. Emebeds are nested. + return included.concat(included.reduce((acc, include) => acc.concat(this._extractEmbeds(include)), [])); + }, + _mergeFields(resourceHash) { // ApiV2 `links` exist outside the attributes field; make them accessible to the data model if (resourceHash.links) { // TODO: Should also test whether model class defines a links field resourceHash.attributes.links = resourceHash.links; } - if (resourceHash.embeds) { - resourceHash.relationships = resourceHash.relationships || {}; - Object.keys(resourceHash.embeds).forEach(embedded => { - resourceHash.relationships[embedded] = resourceHash.relationships[embedded] || {}; - resourceHash.embeds[embedded].type = embedded; - resourceHash.relationships[embedded] = resourceHash.embeds[embedded]; - }); - } + return resourceHash; }, - + + _normalizeDocumentHelper(documentHash) { + documentHash.included = this._extractEmbeds(documentHash.data); + return this._super(documentHash); + }, + extractAttributes(modelClass, resourceHash) { resourceHash = this._mergeFields(resourceHash); return this._super(modelClass, resourceHash); @@ -36,7 +60,7 @@ export default DS.JSONAPISerializer.extend({ } else if (method === 'serialize') { return Ember.String.camelize(key); } - return key; + return key; }, serialize: function(snapshot, options) { From e0f71c08ccff3b9c1865ab202da9b51ab4fdb373 Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Wed, 11 May 2016 11:04:17 -0400 Subject: [PATCH 065/959] Rename users to user on contributors --- addon/serializers/contributor.js | 9 +++++++++ app/serializers/contributor.js | 1 + 2 files changed, 10 insertions(+) create mode 100644 addon/serializers/contributor.js create mode 100644 app/serializers/contributor.js diff --git a/addon/serializers/contributor.js b/addon/serializers/contributor.js new file mode 100644 index 000000000..6b7677257 --- /dev/null +++ b/addon/serializers/contributor.js @@ -0,0 +1,9 @@ +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + extractAttributes(modelClass, resourceHash) { + resourceHash.relationships.user = resourceHash.relationships.users; + delete resourceHash.relationships.users; + return this._super(modelClass, resourceHash); + }, +}); diff --git a/app/serializers/contributor.js b/app/serializers/contributor.js new file mode 100644 index 000000000..fa26840ec --- /dev/null +++ b/app/serializers/contributor.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/contributor'; From 3c8b9dddaccb9fb1f718dfcd7ac24a5407fa2a52 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 11:06:32 -0400 Subject: [PATCH 066/959] Add test BACKEND and fix formatting --- index.js | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index ef70fa2ae..0b9530626 100644 --- a/index.js +++ b/index.js @@ -9,39 +9,44 @@ module.exports = { let SETTINGS = {}; try { SETTINGS = config.get(BACKEND); - } - catch (e) { + } catch (e) { console.log(`WARNING: you have specified a backend '${BACKEND}' that you have not configured in your config/.yml`); } ENV.OSF = { - clientId: SETTINGS.CLIENT_ID, - scope: SETTINGS.OAUTH_SCOPES, - apiNamespace: 'v2' // URL suffix (after host) + clientId: SETTINGS.CLIENT_ID, + scope: SETTINGS.OAUTH_SCOPES, + apiNamespace: 'v2' // URL suffix (after host) }; if (BACKEND === 'local') { - ENV.OSF.url = 'http://localhost:5000/'; - ENV.OSF.apiUrl = 'http://localhost:8000'; - ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; + ENV.OSF.url = 'http://localhost:5000/'; + ENV.OSF.apiUrl = 'http://localhost:8000'; + ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; - ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; - ENV.OSF.isLocal = true; + ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; + ENV.OSF.isLocal = true; } if (BACKEND === 'stage') { - ENV.OSF.url = 'https://staging.osf.io/'; - ENV.OSF.apiUrl = 'https://staging-api.osf.io'; - ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; + ENV.OSF.url = 'https://staging.osf.io/'; + ENV.OSF.apiUrl = 'https://staging-api.osf.io'; + ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; } if (BACKEND === 'stage2') { - ENV.OSF.url = 'https://staging2.osf.io/'; - ENV.OSF.apiUrl = 'https://staging2-api.osf.io'; - ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; + ENV.OSF.url = 'https://staging2.osf.io/'; + ENV.OSF.apiUrl = 'https://staging2-api.osf.io'; + ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; + } + if (BACKEND === 'test') { + ENV.OSF.url = 'https://test.osf.io/'; + ENV.OSF.apiUrl = 'https://test-api.osf.io'; + ENV.OSF.authUrl = 'https://test-accounts.osf.io/oauth2/authorize'; } if (BACKEND === 'prod') { - ENV.OSF.url = 'https://osf.io/'; - ENV.OSF.apiUrl = 'https://api.osf.io'; - ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; + console.log('WARNING: you\'ve specified production as a backend. Please do not use production for testing or development purposes'); + ENV.OSF.url = 'https://osf.io/'; + ENV.OSF.apiUrl = 'https://api.osf.io'; + ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; } ENV['ember-simple-auth'] = { authorizer: 'authorizer:osf-token' From 22c7812ea0bd41ecc3dc1226864a8f2b318d0e2d Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 11:07:12 -0400 Subject: [PATCH 067/959] Replace ember-osf-settings blueprint with default blueprint This blueprint gets added automatically when running ember install ember-osf Also update README --- README.md | 44 ++++++++++--------- blueprints/ember-osf-settings/index.js | 15 ------- .../files/config/_local.yml} | 3 ++ blueprints/ember-osf/index.js | 30 +++++++++++++ index.js | 4 ++ 5 files changed, 61 insertions(+), 35 deletions(-) delete mode 100644 blueprints/ember-osf-settings/index.js rename blueprints/{ember-osf-settings/files/config/__name__.yml => ember-osf/files/config/_local.yml} (85%) create mode 100644 blueprints/ember-osf/index.js diff --git a/README.md b/README.md index 3caa17b90..2a3f5deed 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,19 @@ This repo contains code for interacting with the OSF APIv2 inside of an Ember ap Please read the [CONTRIBUTING.md](https://github.com/CenterForOpenScience/ember-osf/blob/develop/.github/CONTRIBUTING.md) +## Installation (for Development) + +* `git clone` this repository +* `npm install` +* `bower install` + ## Using this code in an Ember app 1. Clone the repository: `git clone https://github.com/CenterForOpenScience/ember-osf.git` 2. From the consuming Ember app: - install the addon and it's dependencies: `ember install ../ember-osf` + - this generates a config/local.yml file (see 'Configuration' below) - link the app for local development: `npm link ../ember-osf` - - generate a settings file (see 'Configuration' below) - Import code from ember-osf like: ```javascript import Ember from 'ember'; @@ -24,23 +30,14 @@ Please read the [CONTRIBUTING.md](https://github.com/CenterForOpenScience/ember- export default Ember.Route.extend(OsfLoginRouteMixin); ``` - -#### Ember Data: Using the OSF models - -The models, serializers, adapters bundled in this addon with be available to you automatically. -For example, simply do: -```javascript -this.store.findAll('node') -``` -to fetch all nodes. -## Installation (for Development) +## Configuration -* `git clone` this repository -* `npm install` -* `bower install` +#### local.yml settings -## Configuration +Edit the new file (installed in the config directory) and set: +- `CLIENT_ID` to the client id of your developer application +- `PERSONAL_ACCESS_TOKEN` to the newly generated token (if applicable, optional for staging development) #### Using the Staging or Test API @@ -54,14 +51,21 @@ personal access token on your local OSF instance ([here](http://localhost:5000/s #### Create a local settings file -To do this: +If for some reason you don't have a config/local.yml you can generate one. To do this: ```bash -ember g ember-osf-settings `echo $HOSTNAME` +ember g ember-osf `echo $HOSTNAME` ``` -Edit the new file (installed in the config directory) and set: -- `CLIENT_ID` to the client id of your developer application -- `PERSONAL_ACCESS_TOKEN` to the newly generated token (if applicable, optional for staging development) +## Usage + +#### Ember Data: Using the OSF models + +The models, serializers, adapters bundled in this addon with be available to you automatically. +For example, simply do: +```javascript +this.store.findAll('node') +``` +to fetch all nodes. ## Running diff --git a/blueprints/ember-osf-settings/index.js b/blueprints/ember-osf-settings/index.js deleted file mode 100644 index aec33ac41..000000000 --- a/blueprints/ember-osf-settings/index.js +++ /dev/null @@ -1,15 +0,0 @@ -/*jshint node:true*/ -module.exports = { - description: '' - - // locals: function(options) { - // // Return custom template variables here. - // return { - // foo: options.entity.options.foo - // }; - // } - - // afterInstall: function(options) { - // // Perform extra work here. - // } -}; diff --git a/blueprints/ember-osf-settings/files/config/__name__.yml b/blueprints/ember-osf/files/config/_local.yml similarity index 85% rename from blueprints/ember-osf-settings/files/config/__name__.yml rename to blueprints/ember-osf/files/config/_local.yml index cdfa042ac..590892b20 100644 --- a/blueprints/ember-osf-settings/files/config/__name__.yml +++ b/blueprints/ember-osf/files/config/_local.yml @@ -1,3 +1,5 @@ + +######## ember-osf settings ######## # local: # CLIENT_ID: null # PERSONAL_ACCESS_TOKEN: null @@ -17,3 +19,4 @@ stage: # CLIENT_ID: null # PERSONAL_ACCESS_TOKEN: null # OAUTH_SCOPES: osf.full_read osf.full_write +######### end ember-osf ########## diff --git a/blueprints/ember-osf/index.js b/blueprints/ember-osf/index.js new file mode 100644 index 000000000..f2aaf2e53 --- /dev/null +++ b/blueprints/ember-osf/index.js @@ -0,0 +1,30 @@ +/*jshint node:true*/ +var fs = require('fs'); +var path = require('path'); + +var CONFIG_MARKER = /#+\s+ember-osf\s+settings\s+#+.*?#+(?:.|\s|\n)*/m; + +module.exports = { + description: '', + normalizeEntityName: function() { + // h/t: https://github.com/samselikoff/ember-cli-mirage/blob/master/blueprints/ember-cli-mirage/index.js + // this prevents an error when the entityName is + // not specified (since that doesn't actually matter + // to us + }, + afterInstall: function() { + var configPath = path.join(this.project.root, 'config', 'local.yml'); + var tmpConfigPath = path.join(this.project.root, 'config', '_local.yml'); + try { + debugger; + var contents = fs.readFileSync(configPath).toString(); + if (!CONFIG_MARKER.test(contents)) { + var tmpConfig = fs.readFileSync(tmpConfigPath).toString(); + fs.appendFileSync(configPath, tmpConfig); + } + fs.unlinkSync(tmpConfigPath); + } catch (e) { + fs.renameSync(tmpConfigPath, configPath); + } + } +}; diff --git a/index.js b/index.js index 0b9530626..a30d3898d 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,13 @@ /* jshint node: true */ 'use strict'; +var path = require('path'); var config = require('config'); module.exports = { name: 'ember-osf', + blueprintsPath: function() { + return path.join(__dirname, 'blueprints'); + }, config: function(environment, ENV) { let BACKEND = process.env.BACKEND || 'local'; let SETTINGS = {}; From 9a6449642bb003fa9afba16f0a6547350be7795b Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 13:03:03 -0400 Subject: [PATCH 068/959] Encourage developers to use tests by default [skip ci] --- README.md | 18 +++++++++++++++--- blueprints/ember-osf/files/config/_local.yml | 16 ++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2a3f5deed..8518c3d56 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,18 @@ Please read the [CONTRIBUTING.md](https://github.com/CenterForOpenScience/ember- #### local.yml settings +This file is structured like: +```yaml +: + CLIENT_ID: null + PERSONAL_ACCESS_TOKEN: null + OAUTH_SCOPES: osf.full_read osf.full_write +``` + +You will need to fill out options for each backend you want to use (see 'Running' below). +We reccomend using the 'test' backend for development and testing as it is the most stable +of our staging enviorments. + Edit the new file (installed in the config directory) and set: - `CLIENT_ID` to the client id of your developer application - `PERSONAL_ACCESS_TOKEN` to the newly generated token (if applicable, optional for staging development) @@ -69,16 +81,16 @@ to fetch all nodes. ## Running -First, decide which backend you would like to target. Typically we reccomend developers use either our staging or test servers: -- staging (`stage`): contains bleeding edge features, but less stable +We reccomend developers target out test server: - test (`test`): matches production features, very stable Other options include: - local (`local`): for developers running the OSF stack locally +- staging (`stage`): contains bleeding edge features, but less stable - staging2 (`stage2`): another version of staging using running a specific feature branch Then (using staging as an example) run: -`BACKEND=stage ember s` +`BACKEND=test ember s` and visit your app at http://localhost:4200. diff --git a/blueprints/ember-osf/files/config/_local.yml b/blueprints/ember-osf/files/config/_local.yml index 590892b20..ac611e261 100644 --- a/blueprints/ember-osf/files/config/_local.yml +++ b/blueprints/ember-osf/files/config/_local.yml @@ -5,18 +5,18 @@ # PERSONAL_ACCESS_TOKEN: null # OAUTH_SCOPES: osf.full_read osf.full_write -stage: - CLIENT_ID: null - PERSONAL_ACCESS_TOKEN: null - OAUTH_SCOPES: osf.full_read osf.full_write +# stage: +# CLIENT_ID: null +# PERSONAL_ACCESS_TOKEN: null +# OAUTH_SCOPES: osf.full_read osf.full_write # stage2: # CLIENT_ID: null # PERSONAL_ACCESS_TOKEN: null # OAUTH_SCOPES: osf.full_read osf.full_write -# test: -# CLIENT_ID: null -# PERSONAL_ACCESS_TOKEN: null -# OAUTH_SCOPES: osf.full_read osf.full_write +test: + CLIENT_ID: null + PERSONAL_ACCESS_TOKEN: null + OAUTH_SCOPES: osf.full_read osf.full_write ######### end ember-osf ########## From 064f2bef32b571e30057fc987dc06503e658d517 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 11 May 2016 13:15:23 -0400 Subject: [PATCH 069/959] File models draft --- addon/adapters/file-provider.js | 7 +++++ addon/models/file-contents.js | 7 +++++ addon/models/file-provider.js | 11 ++++++++ addon/models/file-version.js | 8 ++++++ addon/models/file.js | 26 +++++++++++++++++++ addon/models/node.js | 2 +- app/adapters/file-provider.js | 1 + app/models/file-contents.js | 1 + app/models/file-provider.js | 1 + app/models/file-version.js | 1 + app/models/file.js | 1 + tests/dummy/app/router.js | 6 ++++- tests/dummy/app/routes/nodes/detail/files.js | 8 ++++++ tests/dummy/app/templates/nodes/detail.hbs | 4 +++ .../templates/nodes/detail/files/detail.hbs | 1 + .../templates/nodes/detail/files/index.hbs | 14 ++++++++++ tests/unit/adapters/file-provider-test.js | 12 +++++++++ tests/unit/models/file-contents-test.js | 12 +++++++++ tests/unit/models/file-provider-test.js | 12 +++++++++ tests/unit/models/file-test.js | 12 +++++++++ tests/unit/models/file-version-test.js | 12 +++++++++ 21 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 addon/adapters/file-provider.js create mode 100644 addon/models/file-contents.js create mode 100644 addon/models/file-provider.js create mode 100644 addon/models/file-version.js create mode 100644 addon/models/file.js create mode 100644 app/adapters/file-provider.js create mode 100644 app/models/file-contents.js create mode 100644 app/models/file-provider.js create mode 100644 app/models/file-version.js create mode 100644 app/models/file.js create mode 100644 tests/dummy/app/routes/nodes/detail/files.js create mode 100644 tests/dummy/app/templates/nodes/detail/files/detail.hbs create mode 100644 tests/dummy/app/templates/nodes/detail/files/index.hbs create mode 100644 tests/unit/adapters/file-provider-test.js create mode 100644 tests/unit/models/file-contents-test.js create mode 100644 tests/unit/models/file-provider-test.js create mode 100644 tests/unit/models/file-test.js create mode 100644 tests/unit/models/file-version-test.js diff --git a/addon/adapters/file-provider.js b/addon/adapters/file-provider.js new file mode 100644 index 000000000..764b4a93a --- /dev/null +++ b/addon/adapters/file-provider.js @@ -0,0 +1,7 @@ +import JSONAPIAdapter from 'ember-data/adapters/json-api'; + +export default JSONAPIAdapter.extend({ + pathForType(type) { + return 'files'; + } +}); diff --git a/addon/models/file-contents.js b/addon/models/file-contents.js new file mode 100644 index 000000000..ec0a39394 --- /dev/null +++ b/addon/models/file-contents.js @@ -0,0 +1,7 @@ +//import DS from 'ember-data'; + +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ + // TODO waterbutler file +}); diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js new file mode 100644 index 000000000..da610dbc6 --- /dev/null +++ b/addon/models/file-provider.js @@ -0,0 +1,11 @@ +import DS from 'ember-data'; + +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ + name: DS.attr('string'), + kind: DS.attr('string'), + path: DS.attr('string'), + files: DS.hasMany('file'), // TODO only files/folders in root + node: DS.belongsTo('node') +}); diff --git a/addon/models/file-version.js b/addon/models/file-version.js new file mode 100644 index 000000000..51165f08e --- /dev/null +++ b/addon/models/file-version.js @@ -0,0 +1,8 @@ +import DS from 'ember-data'; + +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ + size: DS.attr('number'), + contentType: DS.attr('string'), +}); diff --git a/addon/models/file.js b/addon/models/file.js new file mode 100644 index 000000000..3d1840790 --- /dev/null +++ b/addon/models/file.js @@ -0,0 +1,26 @@ +import DS from 'ember-data'; + +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ + name: DS.attr('string'), + kind: DS.attr('string'), + size: DS.attr('number'), + path: DS.attr('string'), + materializedPath: DS.attr('string'), + lastTouched: DS.attr('date'), + dateModified: DS.attr('date'), + dateCreated: DS.attr('date'), + + provider: DS.belongsTo('file-provider'), + parentFolder: DS.belongsTo('file'), + extra: DS.attr(), + + // Folder attributes + children: DS.hasMany('file'), + + // File attributes + versions: DS.hasMany('file-version'), + comments: DS.hasMany('comment'), + contents: DS.belongsTo('file-contents') +}); diff --git a/addon/models/node.js b/addon/models/node.js index df7e0778e..ef32840e4 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -30,7 +30,7 @@ export default OsfModel.extend({ comments: DS.hasMany('comments'), contributors: DS.hasMany('contributors'), - //files: DS.hasMany('files'), + fileProviders: DS.hasMany('file-provider'), //forkedFrom: DS.belongsTo('node'), //nodeLinks: DS.hasMany('node-pointers'), //registrations: DS.hasMany('registrations'), diff --git a/app/adapters/file-provider.js b/app/adapters/file-provider.js new file mode 100644 index 000000000..59172b38c --- /dev/null +++ b/app/adapters/file-provider.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/file-provider'; diff --git a/app/models/file-contents.js b/app/models/file-contents.js new file mode 100644 index 000000000..a9bf42148 --- /dev/null +++ b/app/models/file-contents.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/file-contents'; diff --git a/app/models/file-provider.js b/app/models/file-provider.js new file mode 100644 index 000000000..271da3e54 --- /dev/null +++ b/app/models/file-provider.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/file-provider'; diff --git a/app/models/file-version.js b/app/models/file-version.js new file mode 100644 index 000000000..3048fb088 --- /dev/null +++ b/app/models/file-version.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/file-version'; diff --git a/app/models/file.js b/app/models/file.js new file mode 100644 index 000000000..b9cd8fd03 --- /dev/null +++ b/app/models/file.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/file'; diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index dc7d751eb..242a4d2b6 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -8,7 +8,11 @@ const Router = Ember.Router.extend({ Router.map(function() { this.route('index', {path: '/'}); this.route('nodes', function() { - this.route('detail', {path: '/:node_id'}); + this.route('detail', {path: '/:node_id'}, function() { + this.route('files', function() { + this.route('detail', {path: '/:file_id'}); + }); + }); }); this.route('login'); }); diff --git a/tests/dummy/app/routes/nodes/detail/files.js b/tests/dummy/app/routes/nodes/detail/files.js new file mode 100644 index 000000000..d959fd487 --- /dev/null +++ b/tests/dummy/app/routes/nodes/detail/files.js @@ -0,0 +1,8 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model() { + let node = this.modelFor('nodes.detail'); + return node.fileProviders; + } +}); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 05bba69c0..32ffc8a32 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -11,6 +11,10 @@ View on OSF

+

+ {{link-to 'View files' 'nodes.detail.files' model.id + class='btn btn-primary'}} +


Contributors

diff --git a/tests/dummy/app/templates/nodes/detail/files/detail.hbs b/tests/dummy/app/templates/nodes/detail/files/detail.hbs new file mode 100644 index 000000000..a9bffd75c --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/files/detail.hbs @@ -0,0 +1 @@ +

Hi there

diff --git a/tests/dummy/app/templates/nodes/detail/files/index.hbs b/tests/dummy/app/templates/nodes/detail/files/index.hbs new file mode 100644 index 000000000..bc4d7acda --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/files/index.hbs @@ -0,0 +1,14 @@ +{{link-to 'Back to node' 'nodes.detail' model.node class="btn btn-default"}} +
+{{#each model as |provider|}} +

{{provider.name}}

+

{{provider.kind}}

+

{{provider.path}}

+

+ Files: + {{#each provider.files as |file|}} +

{{file.name}}

+ {{/each}} +

+{{/each}} +
diff --git a/tests/unit/adapters/file-provider-test.js b/tests/unit/adapters/file-provider-test.js new file mode 100644 index 000000000..3fea566c9 --- /dev/null +++ b/tests/unit/adapters/file-provider-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:file-provider', 'Unit | Adapter | file provider', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/models/file-contents-test.js b/tests/unit/models/file-contents-test.js new file mode 100644 index 000000000..732f1ac43 --- /dev/null +++ b/tests/unit/models/file-contents-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('file-contents', 'Unit | Model | file contents', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/models/file-provider-test.js b/tests/unit/models/file-provider-test.js new file mode 100644 index 000000000..292afd2c3 --- /dev/null +++ b/tests/unit/models/file-provider-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('file-provider', 'Unit | Model | file provider', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/models/file-test.js b/tests/unit/models/file-test.js new file mode 100644 index 000000000..225d0728a --- /dev/null +++ b/tests/unit/models/file-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('file', 'Unit | Model | file', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/models/file-version-test.js b/tests/unit/models/file-version-test.js new file mode 100644 index 000000000..39e5ed69a --- /dev/null +++ b/tests/unit/models/file-version-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('file-version', 'Unit | Model | file version', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); From 2bd8ccc8b49571b4362eb6af7b7f628ee8c9a88f Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 11 May 2016 14:33:51 -0400 Subject: [PATCH 070/959] Can fetch a node's file providers (WIP) --- addon/adapters/file-provider.js | 2 +- addon/models/file.js | 9 +++ addon/models/node.js | 2 +- tests/dummy/app/router.js | 8 +-- tests/dummy/app/routes/nodes/detail/files.js | 6 +- tests/dummy/app/templates/nodes/detail.hbs | 43 +------------- .../app/templates/nodes/detail/files.hbs | 8 +++ .../templates/nodes/detail/files/detail.hbs | 1 - .../templates/nodes/detail/files/index.hbs | 14 ----- .../app/templates/nodes/detail/index.hbs | 57 +++++++++++++++++++ 10 files changed, 82 insertions(+), 68 deletions(-) create mode 100644 tests/dummy/app/templates/nodes/detail/files.hbs delete mode 100644 tests/dummy/app/templates/nodes/detail/files/detail.hbs delete mode 100644 tests/dummy/app/templates/nodes/detail/files/index.hbs create mode 100644 tests/dummy/app/templates/nodes/detail/index.hbs diff --git a/addon/adapters/file-provider.js b/addon/adapters/file-provider.js index 764b4a93a..2410cbdfa 100644 --- a/addon/adapters/file-provider.js +++ b/addon/adapters/file-provider.js @@ -1,7 +1,7 @@ import JSONAPIAdapter from 'ember-data/adapters/json-api'; export default JSONAPIAdapter.extend({ - pathForType(type) { + pathForType() { return 'files'; } }); diff --git a/addon/models/file.js b/addon/models/file.js index 3d1840790..b9e80d967 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -3,6 +3,7 @@ import DS from 'ember-data'; import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ + /* FILE model name: DS.attr('string'), kind: DS.attr('string'), size: DS.attr('number'), @@ -23,4 +24,12 @@ export default OsfModel.extend({ versions: DS.hasMany('file-version'), comments: DS.hasMany('comment'), contents: DS.belongsTo('file-contents') + */ + + // FileProvider model + name: DS.attr('string'), + kind: DS.attr('string'), + path: DS.attr('string'), + files: DS.hasMany('file'), // TODO only files/folders in root + node: DS.belongsTo('node') }); diff --git a/addon/models/node.js b/addon/models/node.js index ef32840e4..0c22b63fa 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -30,7 +30,7 @@ export default OsfModel.extend({ comments: DS.hasMany('comments'), contributors: DS.hasMany('contributors'), - fileProviders: DS.hasMany('file-provider'), + files: DS.hasMany('file'), //forkedFrom: DS.belongsTo('node'), //nodeLinks: DS.hasMany('node-pointers'), //registrations: DS.hasMany('registrations'), diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 242a4d2b6..cddbcee97 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -8,11 +8,9 @@ const Router = Ember.Router.extend({ Router.map(function() { this.route('index', {path: '/'}); this.route('nodes', function() { - this.route('detail', {path: '/:node_id'}, function() { - this.route('files', function() { - this.route('detail', {path: '/:file_id'}); - }); - }); + this.route('detail', {path: '/:node_id'}, function() { + this.route('files'); + }); }); this.route('login'); }); diff --git a/tests/dummy/app/routes/nodes/detail/files.js b/tests/dummy/app/routes/nodes/detail/files.js index d959fd487..cdf1f982b 100644 --- a/tests/dummy/app/routes/nodes/detail/files.js +++ b/tests/dummy/app/routes/nodes/detail/files.js @@ -1,8 +1,6 @@ import Ember from 'ember'; export default Ember.Route.extend({ - model() { - let node = this.modelFor('nodes.detail'); - return node.fileProviders; - } + //afterModel(model) { + //} }); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 32ffc8a32..e2147cab0 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -1,42 +1 @@ -{{link-to 'Back to list' 'nodes' class="btn btn-default"}} -
- -

Data

-

{{model.title}}

-

{{model.category}}

-

{{moment-format model.dateCreated}}

-

{{moment-format model.dateModified}}

-

- - View on OSF - -

-

- {{link-to 'View files' 'nodes.detail.files' model.id - class='btn btn-primary'}} -

-
- -

Contributors

- - - - - - - {{#each model.contributors as |contrib|}} - - - - - {{/each}} -
IDAuthor?
{{contrib.id}}{{contrib.bibliographic}}
- - - -

Edit this node

- Title: {{input value=editedTitle}} - - -
- +{{outlet}} \ No newline at end of file diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs new file mode 100644 index 000000000..dd7a0fcbd --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/files.hbs @@ -0,0 +1,8 @@ +{{link-to 'Back to node' 'nodes.detail' model class="btn btn-default"}} +
+{{#each model.fileProviders as |provider|}} +

{{provider.name}}

+

{{provider.kind}}

+

{{provider.path}}

+{{/each}} +
diff --git a/tests/dummy/app/templates/nodes/detail/files/detail.hbs b/tests/dummy/app/templates/nodes/detail/files/detail.hbs deleted file mode 100644 index a9bffd75c..000000000 --- a/tests/dummy/app/templates/nodes/detail/files/detail.hbs +++ /dev/null @@ -1 +0,0 @@ -

Hi there

diff --git a/tests/dummy/app/templates/nodes/detail/files/index.hbs b/tests/dummy/app/templates/nodes/detail/files/index.hbs deleted file mode 100644 index bc4d7acda..000000000 --- a/tests/dummy/app/templates/nodes/detail/files/index.hbs +++ /dev/null @@ -1,14 +0,0 @@ -{{link-to 'Back to node' 'nodes.detail' model.node class="btn btn-default"}} -
-{{#each model as |provider|}} -

{{provider.name}}

-

{{provider.kind}}

-

{{provider.path}}

-

- Files: - {{#each provider.files as |file|}} -

{{file.name}}

- {{/each}} -

-{{/each}} -
diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs new file mode 100644 index 000000000..ac3fb0889 --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -0,0 +1,57 @@ +{{link-to 'Back to list' 'nodes' class="btn btn-default"}} +
+ +

Data

+

{{model.title}}

+

{{model.category}}

+

{{moment-format model.dateCreated}}

+

{{moment-format model.dateModified}}

+

+ + View on OSF + +

+
+ +

Contributors

+ + + + + + + {{#each model.contributors as |contrib|}} + + + + + {{/each}} +
IDAuthor?
{{contrib.id}}{{contrib.bibliographic}}
+ + + +

Edit this node

+ Title: {{input value=editedTitle}} + + +
+ +

File Providers

+ + + + + + + + {{#each model.files as |provider|}} + + + + + + {{/each}} +
NameKindPath
{{provider.name}}{{provider.kind}}{{provider.path}}
+
+ +{{outlet}} From 8941b8613a97df8516467ee26ea5c80493176243 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 11 May 2016 14:51:03 -0400 Subject: [PATCH 071/959] Gitignore everything in .idea/ directory. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f3e1637c8..309abf092 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ npm-debug.log testem.log config/*.yml +.idea/ From 5f7bc42ec5c6254ee0bf2a938efe462f8ce48d50 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 11 May 2016 15:10:49 -0400 Subject: [PATCH 072/959] Figure out ember a little bit more --- addon/models/file-provider.js | 7 ++++--- addon/models/file.js | 24 ++++++++---------------- addon/models/node.js | 2 +- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index da610dbc6..3ad9340d6 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -3,9 +3,10 @@ import DS from 'ember-data'; import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ - name: DS.attr('string'), kind: DS.attr('string'), + name: DS.attr('string'), path: DS.attr('string'), - files: DS.hasMany('file'), // TODO only files/folders in root - node: DS.belongsTo('node') + //node: DS.belongsTo('node'), + provider: DS.attr('string'), + //files: DS.attr() //.hasMany('file'), }); diff --git a/addon/models/file.js b/addon/models/file.js index b9e80d967..0a9c6fd0a 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -3,33 +3,25 @@ import DS from 'ember-data'; import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ - /* FILE model name: DS.attr('string'), kind: DS.attr('string'), - size: DS.attr('number'), path: DS.attr('string'), + size: DS.attr('number'), + provider: DS.belongsTo('string'), + materializedPath: DS.attr('string'), lastTouched: DS.attr('date'), dateModified: DS.attr('date'), dateCreated: DS.attr('date'), - provider: DS.belongsTo('file-provider'), parentFolder: DS.belongsTo('file'), - extra: DS.attr(), + extra: DS.attr(), // Folder attributes - children: DS.hasMany('file'), + //files: DS.hasMany('file'), // File attributes - versions: DS.hasMany('file-version'), - comments: DS.hasMany('comment'), - contents: DS.belongsTo('file-contents') - */ - - // FileProvider model - name: DS.attr('string'), - kind: DS.attr('string'), - path: DS.attr('string'), - files: DS.hasMany('file'), // TODO only files/folders in root - node: DS.belongsTo('node') + //versions: DS.hasMany('file-version'), + //comments: DS.hasMany('comment'), + //contents: DS.belongsTo('file-contents') }); diff --git a/addon/models/node.js b/addon/models/node.js index 0c22b63fa..c58f843c6 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -30,7 +30,7 @@ export default OsfModel.extend({ comments: DS.hasMany('comments'), contributors: DS.hasMany('contributors'), - files: DS.hasMany('file'), + files: DS.hasMany('file-provider'), //forkedFrom: DS.belongsTo('node'), //nodeLinks: DS.hasMany('node-pointers'), //registrations: DS.hasMany('registrations'), From 1dc36e2f87a7f62a501d11670116fd1ba5569875 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 15:10:41 -0400 Subject: [PATCH 073/959] Fix language and indentation [skip ci] --- README.md | 10 +++++----- blueprints/ember-osf/index.js | 27 +++++++++++++-------------- index.js | 6 +++--- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 8518c3d56..7d80714e5 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ This file is structured like: ``` You will need to fill out options for each backend you want to use (see 'Running' below). -We reccomend using the 'test' backend for development and testing as it is the most stable -of our staging enviorments. +We recommend using the 'test' backend for development and testing as it is the most stable +of our environments. Edit the new file (installed in the config directory) and set: - `CLIENT_ID` to the client id of your developer application @@ -65,7 +65,7 @@ personal access token on your local OSF instance ([here](http://localhost:5000/s If for some reason you don't have a config/local.yml you can generate one. To do this: ```bash -ember g ember-osf `echo $HOSTNAME` +ember generate ember-osf ``` ## Usage @@ -81,7 +81,7 @@ to fetch all nodes. ## Running -We reccomend developers target out test server: +We recommend developers target out test server: - test (`test`): matches production features, very stable Other options include: @@ -90,7 +90,7 @@ Other options include: - staging2 (`stage2`): another version of staging using running a specific feature branch Then (using staging as an example) run: -`BACKEND=test ember s` +`BACKEND=test ember server` and visit your app at http://localhost:4200. diff --git a/blueprints/ember-osf/index.js b/blueprints/ember-osf/index.js index f2aaf2e53..559fb60d0 100644 --- a/blueprints/ember-osf/index.js +++ b/blueprints/ember-osf/index.js @@ -7,24 +7,23 @@ var CONFIG_MARKER = /#+\s+ember-osf\s+settings\s+#+.*?#+(?:.|\s|\n)*/m; module.exports = { description: '', normalizeEntityName: function() { - // h/t: https://github.com/samselikoff/ember-cli-mirage/blob/master/blueprints/ember-cli-mirage/index.js + // h/t: https://github.com/samselikoff/ember-cli-mirage/blob/master/blueprints/ember-cli-mirage/index.js // this prevents an error when the entityName is // not specified (since that doesn't actually matter // to us }, afterInstall: function() { - var configPath = path.join(this.project.root, 'config', 'local.yml'); - var tmpConfigPath = path.join(this.project.root, 'config', '_local.yml'); - try { - debugger; - var contents = fs.readFileSync(configPath).toString(); - if (!CONFIG_MARKER.test(contents)) { - var tmpConfig = fs.readFileSync(tmpConfigPath).toString(); - fs.appendFileSync(configPath, tmpConfig); - } - fs.unlinkSync(tmpConfigPath); - } catch (e) { - fs.renameSync(tmpConfigPath, configPath); - } + var configPath = path.join(this.project.root, 'config', 'local.yml'); + var tmpConfigPath = path.join(this.project.root, 'config', '_local.yml'); + try { + var contents = fs.readFileSync(configPath).toString(); + if (!CONFIG_MARKER.test(contents)) { + var tmpConfig = fs.readFileSync(tmpConfigPath).toString(); + fs.appendFileSync(configPath, tmpConfig); + } + fs.unlinkSync(tmpConfigPath); + } catch (e) { + fs.renameSync(tmpConfigPath, configPath); + } } }; diff --git a/index.js b/index.js index a30d3898d..7e1e5c9f5 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ var config = require('config'); module.exports = { name: 'ember-osf', blueprintsPath: function() { - return path.join(__dirname, 'blueprints'); + return path.join(__dirname, 'blueprints'); }, config: function(environment, ENV) { let BACKEND = process.env.BACKEND || 'local'; @@ -14,7 +14,7 @@ module.exports = { try { SETTINGS = config.get(BACKEND); } catch (e) { - console.log(`WARNING: you have specified a backend '${BACKEND}' that you have not configured in your config/.yml`); + console.log(`WARNING: you have specified a backend '${BACKEND}' that you have not configured in your config/local.yml`); } ENV.OSF = { @@ -47,7 +47,7 @@ module.exports = { ENV.OSF.authUrl = 'https://test-accounts.osf.io/oauth2/authorize'; } if (BACKEND === 'prod') { - console.log('WARNING: you\'ve specified production as a backend. Please do not use production for testing or development purposes'); + console.log('WARNING: you\'ve specified production as a backend. Please do not use production for testing or development purposes'); ENV.OSF.url = 'https://osf.io/'; ENV.OSF.apiUrl = 'https://api.osf.io'; ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; From 570b07d309d6ecf6b01848b5e0fcc458acf9ee9f Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 11 May 2016 15:44:31 -0400 Subject: [PATCH 074/959] Fetch file info for a node and provider --- addon/adapters/file-provider.js | 4 ++-- addon/models/file-provider.js | 2 +- addon/models/file.js | 8 ++++---- addon/serializers/file-provider.js | 7 +++++++ app/serializers/file-provider.js | 1 + tests/dummy/app/templates/nodes/detail/files.hbs | 2 +- tests/dummy/app/templates/nodes/detail/index.hbs | 6 ++++++ tests/unit/serializers/file-provider-test.js | 15 +++++++++++++++ 8 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 addon/serializers/file-provider.js create mode 100644 app/serializers/file-provider.js create mode 100644 tests/unit/serializers/file-provider-test.js diff --git a/addon/adapters/file-provider.js b/addon/adapters/file-provider.js index 2410cbdfa..1f527b735 100644 --- a/addon/adapters/file-provider.js +++ b/addon/adapters/file-provider.js @@ -1,6 +1,6 @@ -import JSONAPIAdapter from 'ember-data/adapters/json-api'; +import ApplicationAdapter from './application'; -export default JSONAPIAdapter.extend({ +export default ApplicationAdapter.extend({ pathForType() { return 'files'; } diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index 3ad9340d6..a8d4ac2ea 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -8,5 +8,5 @@ export default OsfModel.extend({ path: DS.attr('string'), //node: DS.belongsTo('node'), provider: DS.attr('string'), - //files: DS.attr() //.hasMany('file'), + files: DS.hasMany('file'), }); diff --git a/addon/models/file.js b/addon/models/file.js index 0a9c6fd0a..4fcaad6b8 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -18,10 +18,10 @@ export default OsfModel.extend({ extra: DS.attr(), // Folder attributes - //files: DS.hasMany('file'), + files: DS.hasMany('file', {inverse: 'parentFolder'}), // File attributes - //versions: DS.hasMany('file-version'), - //comments: DS.hasMany('comment'), - //contents: DS.belongsTo('file-contents') + versions: DS.hasMany('file-version'), + comments: DS.hasMany('comment'), + contents: DS.belongsTo('file-contents') }); diff --git a/addon/serializers/file-provider.js b/addon/serializers/file-provider.js new file mode 100644 index 000000000..74c6b1e30 --- /dev/null +++ b/addon/serializers/file-provider.js @@ -0,0 +1,7 @@ +import JSONAPISerializer from 'ember-data/serializers/json-api'; + +export default JSONAPISerializer.extend({ + modelNameFromPayloadKey() { + return "file-provider"; + } +}); diff --git a/app/serializers/file-provider.js b/app/serializers/file-provider.js new file mode 100644 index 000000000..8055c5999 --- /dev/null +++ b/app/serializers/file-provider.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/file-provider'; diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs index dd7a0fcbd..94ce0cd5a 100644 --- a/tests/dummy/app/templates/nodes/detail/files.hbs +++ b/tests/dummy/app/templates/nodes/detail/files.hbs @@ -1,6 +1,6 @@ {{link-to 'Back to node' 'nodes.detail' model class="btn btn-default"}}
-{{#each model.fileProviders as |provider|}} +{{#each model.files as |provider|}}

{{provider.name}}

{{provider.kind}}

{{provider.path}}

diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index ac3fb0889..5c58f6eee 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -43,12 +43,18 @@ Name Kind Path + Filenames {{#each model.files as |provider|}} {{provider.name}} {{provider.kind}} {{provider.path}} + + {{#each provider.files as |file|}} +

{{file.name}}

+ {{/each}} + {{/each}} diff --git a/tests/unit/serializers/file-provider-test.js b/tests/unit/serializers/file-provider-test.js new file mode 100644 index 000000000..8843093de --- /dev/null +++ b/tests/unit/serializers/file-provider-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('file-provider', 'Unit | Serializer | file provider', { + // Specify the other units that are required for this test. + needs: ['serializer:file-provider'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); From 989ca238adcc823c89f456644cb302183762fa4c Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Mon, 9 May 2016 14:07:29 -0400 Subject: [PATCH 075/959] Add institutions part one --- addon/models/institution.js | 21 ++++++++++++++ addon/models/node.js | 3 ++ addon/models/user.js | 6 +++- app/models/institution.js | 1 + tests/dummy/app/router.js | 4 +++ tests/dummy/app/routes/institutions.js | 7 +++++ tests/dummy/app/templates/index.hbs | 1 + tests/dummy/app/templates/institutions.hbs | 1 + .../app/templates/institutions/detail.hbs | 28 +++++++++++++++++++ .../app/templates/institutions/index.hbs | 16 +++++++++++ tests/unit/models/institution-test.js | 12 ++++++++ 11 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 addon/models/institution.js create mode 100644 app/models/institution.js create mode 100644 tests/dummy/app/routes/institutions.js create mode 100644 tests/dummy/app/templates/institutions.hbs create mode 100644 tests/dummy/app/templates/institutions/detail.hbs create mode 100644 tests/dummy/app/templates/institutions/index.hbs create mode 100644 tests/unit/models/institution-test.js diff --git a/addon/models/institution.js b/addon/models/institution.js new file mode 100644 index 000000000..1e8538166 --- /dev/null +++ b/addon/models/institution.js @@ -0,0 +1,21 @@ +import DS from 'ember-data'; + +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ + name: DS.attr('string'), + description: DS.attr('string'), + logo_path: DS.attr('string'), + auth_url: DS.attr('strign'), + + children: DS.hasMany('users', { + inverse: 'affiliated_institutions' + }), + nodes: DS.hasMany('nodes', { + inverse: 'affiliated_institutions' + }), + registrations: DS.hasMany('registrations', { + inverse: 'affiliated_institutions' + }), + +}); diff --git a/addon/models/node.js b/addon/models/node.js index df7e0778e..622a9cac9 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -27,6 +27,9 @@ export default OsfModel.extend({ children: DS.hasMany('nodes', { inverse: 'parent' }), + affiliated_institutions: DS.hasMany('institutions', { + inverse: 'nodes' + }), comments: DS.hasMany('comments'), contributors: DS.hasMany('contributors'), diff --git a/addon/models/user.js b/addon/models/user.js index 0076a5c79..7b54a50c0 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -7,5 +7,9 @@ export default OsfModel.extend({ middle_names: DS.attr(), family_name: DS.attr('string'), - nodes: DS.hasMany('nodes') + nodes: DS.hasMany('nodes'), + + affiliated_institutions: DS.hasMany('institutions', { + inverse: 'users' + }), }); diff --git a/app/models/institution.js b/app/models/institution.js new file mode 100644 index 000000000..11f7568c8 --- /dev/null +++ b/app/models/institution.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/institution'; diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index dc7d751eb..47d5cbc33 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -6,11 +6,15 @@ const Router = Ember.Router.extend({ }); Router.map(function() { + this.route('index', {path: '/'}); this.route('nodes', function() { this.route('detail', {path: '/:node_id'}); }); this.route('login'); + this.route('institutions', function() { + this.route('detail', {path: '/:institution_id'}); + }); }); export default Router; diff --git a/tests/dummy/app/routes/institutions.js b/tests/dummy/app/routes/institutions.js new file mode 100644 index 000000000..803170577 --- /dev/null +++ b/tests/dummy/app/routes/institutions.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model() { + return this.store.findAll('institutions'); + } +}); diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs index 40bbcc845..7d7111420 100644 --- a/tests/dummy/app/templates/index.hbs +++ b/tests/dummy/app/templates/index.hbs @@ -1 +1,2 @@ {{link-to 'My Nodes' 'nodes' class="btn btn-default"}} +{{link-to 'All Institutions' 'institutions' class="btn btn-danger"}} diff --git a/tests/dummy/app/templates/institutions.hbs b/tests/dummy/app/templates/institutions.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/tests/dummy/app/templates/institutions.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/tests/dummy/app/templates/institutions/detail.hbs b/tests/dummy/app/templates/institutions/detail.hbs new file mode 100644 index 000000000..5fb539e02 --- /dev/null +++ b/tests/dummy/app/templates/institutions/detail.hbs @@ -0,0 +1,28 @@ +{{link-to 'Back to list' 'institutions' class="btn btn-default"}} +
+

{{model.name}}

+

{{model.description}}

+

{{model.logo_url}}

+

{{model.auth_url}}

+

+ + View on OSF + +

+
+

+ +

+ + {{#each model.nodes as |node|}} + + {{node.title}} + + + {{node.description}} + + {{/each}} +
+

+

+
diff --git a/tests/dummy/app/templates/institutions/index.hbs b/tests/dummy/app/templates/institutions/index.hbs new file mode 100644 index 000000000..90e2fb573 --- /dev/null +++ b/tests/dummy/app/templates/institutions/index.hbs @@ -0,0 +1,16 @@ +

All Institutions

+{{#each model as |inst|}} +
+
+

{{inst.name}}

+

{{inst.description}}

+

{{inst.logo_url}}

+

{{inst.auth_url}}

+

+ + View on OSF + + {{link-to 'Detail' 'institutions.detail' inst.id class="btn btn-primary"}} +

+
+{{/each}} diff --git a/tests/unit/models/institution-test.js b/tests/unit/models/institution-test.js new file mode 100644 index 000000000..1857242b4 --- /dev/null +++ b/tests/unit/models/institution-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('institution', 'Unit | Model | institution', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); From 69fbfe6e1a2b04f9302748cc1e53b18296ecaf29 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Mon, 9 May 2016 14:36:04 -0400 Subject: [PATCH 076/959] point to right endpoint --- tests/dummy/app/routes/institutions.js | 2 +- tests/dummy/app/templates/nodes/detail.hbs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/dummy/app/routes/institutions.js b/tests/dummy/app/routes/institutions.js index 803170577..52436fea8 100644 --- a/tests/dummy/app/routes/institutions.js +++ b/tests/dummy/app/routes/institutions.js @@ -2,6 +2,6 @@ import Ember from 'ember'; export default Ember.Route.extend({ model() { - return this.store.findAll('institutions'); + return this.store.findAll('institution'); } }); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 05bba69c0..ed187c12d 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -35,4 +35,3 @@
- From 1b15fc3b5a6b5d2d7d64bc98ed7e379cefd5da13 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Mon, 9 May 2016 15:01:03 -0400 Subject: [PATCH 077/959] fix registrations --- addon/models/institution.js | 2 +- addon/models/registration.js | 10 ++++++++++ app/models/registration.js | 1 + tests/unit/models/registration-test.js | 12 ++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 addon/models/registration.js create mode 100644 app/models/registration.js create mode 100644 tests/unit/models/registration-test.js diff --git a/addon/models/institution.js b/addon/models/institution.js index 1e8538166..7bd38ea87 100644 --- a/addon/models/institution.js +++ b/addon/models/institution.js @@ -6,7 +6,7 @@ export default OsfModel.extend({ name: DS.attr('string'), description: DS.attr('string'), logo_path: DS.attr('string'), - auth_url: DS.attr('strign'), + auth_url: DS.attr('string'), children: DS.hasMany('users', { inverse: 'affiliated_institutions' diff --git a/addon/models/registration.js b/addon/models/registration.js new file mode 100644 index 000000000..9e4566122 --- /dev/null +++ b/addon/models/registration.js @@ -0,0 +1,10 @@ +import DS from 'ember-data'; + +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ + title: DS.attr('string'), + affiliated_institutions: DS.hasMany('institutions', { + inverse: 'registrations' + }), +}); diff --git a/app/models/registration.js b/app/models/registration.js new file mode 100644 index 000000000..771101b41 --- /dev/null +++ b/app/models/registration.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/registration'; diff --git a/tests/unit/models/registration-test.js b/tests/unit/models/registration-test.js new file mode 100644 index 000000000..2b091c1ed --- /dev/null +++ b/tests/unit/models/registration-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('registration', 'Unit | Model | registration', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); From 996f4fcae7f1e22b4ea25380b1c34a9b71984a01 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Mon, 9 May 2016 15:29:06 -0400 Subject: [PATCH 078/959] clean ip --- addon/models/node.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addon/models/node.js b/addon/models/node.js index 622a9cac9..5dab50e08 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -37,7 +37,6 @@ export default OsfModel.extend({ //forkedFrom: DS.belongsTo('node'), //nodeLinks: DS.hasMany('node-pointers'), //registrations: DS.hasMany('registrations'), - //primaryInstitution: DS.belongsTo('institution'), root: DS.belongsTo('node') //logs: DS.hasMany('node-logs'), }); From 28a5595188d19602e806300d14f5289ef7987b8c Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Tue, 10 May 2016 10:57:09 -0400 Subject: [PATCH 079/959] add registrations --- addon/models/node.js | 8 ++++-- addon/models/registration.js | 33 +++++++++++++++++++++- index.js | 1 + tests/dummy/app/router.js | 6 +++- tests/dummy/app/templates/index.hbs | 1 + tests/dummy/app/templates/nodes/detail.hbs | 2 -- 6 files changed, 45 insertions(+), 6 deletions(-) diff --git a/addon/models/node.js b/addon/models/node.js index 5dab50e08..a066c5c64 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -27,7 +27,7 @@ export default OsfModel.extend({ children: DS.hasMany('nodes', { inverse: 'parent' }), - affiliated_institutions: DS.hasMany('institutions', { + affiliatedInstitutions: DS.hasMany('institutions', { inverse: 'nodes' }), comments: DS.hasMany('comments'), @@ -36,7 +36,11 @@ export default OsfModel.extend({ //files: DS.hasMany('files'), //forkedFrom: DS.belongsTo('node'), //nodeLinks: DS.hasMany('node-pointers'), - //registrations: DS.hasMany('registrations'), + registrations: DS.hasMany('registrations', { + inverse: 'registeredFrom' + }), + + root: DS.belongsTo('node') //logs: DS.hasMany('node-logs'), }); diff --git a/addon/models/registration.js b/addon/models/registration.js index 9e4566122..c8e84ab90 100644 --- a/addon/models/registration.js +++ b/addon/models/registration.js @@ -4,7 +4,38 @@ import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ title: DS.attr('string'), - affiliated_institutions: DS.hasMany('institutions', { + registration: DS.attr('boolean'), + public: DS.attr('boolean'), + category: DS.attr('string'), + fork: DS.attr('boolean'), + description: DS.attr('string'), + collection: DS.attr('boolean'), + + dateCreated: DS.attr('date'), + dateModified: DS.attr('date'), + dateRegistered: DS.attr('date'), + + pendingRegistrationApproval: DS.attr('boolean'), + + embargoEndDate: DS.attr('date'), + pendingEmbargoApproval: DS.attr('boolean'), + withdrawn: DS.attr('boolean'), + withdrawalJustification: DS.attr('string'), + pendingWithdrawal: DS.attr('boolean'), + + registrationSupplement: DS.attr('string'), + registeredMeta: DS.attr(), + tags: DS.attr(), + + affiliatedInstitutions: DS.hasMany('institutions', { inverse: 'registrations' }), + registeredFrom: DS.belongsTo('node', { + inverse: 'registrations' + }), + registeredBy: DS.belongsTo('user'), + contributors: DS.hasMany('contributors'), + comments: DS.hasMany('comments'), + //more relationship + }); diff --git a/index.js b/index.js index 7e1e5c9f5..8e8ea7af1 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ module.exports = { return path.join(__dirname, 'blueprints'); }, config: function(environment, ENV) { + let BACKEND = process.env.BACKEND || 'local'; let SETTINGS = {}; try { diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 47d5cbc33..76b5e4825 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -13,8 +13,12 @@ Router.map(function() { }); this.route('login'); this.route('institutions', function() { - this.route('detail', {path: '/:institution_id'}); + this.route('detail', {path: '/:institution_id'}); }); + this.route('registrations', function() { + this.route('detail', {path: '/:registration_id'}) + }); + }); export default Router; diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs index 7d7111420..09bd11953 100644 --- a/tests/dummy/app/templates/index.hbs +++ b/tests/dummy/app/templates/index.hbs @@ -1,2 +1,3 @@ {{link-to 'My Nodes' 'nodes' class="btn btn-default"}} +{{link-to 'My Registrations' 'registrations' class="btn btn-warning"}} {{link-to 'All Institutions' 'institutions' class="btn btn-danger"}} diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index ed187c12d..db6f34f89 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -28,8 +28,6 @@ {{/each}} - -

Edit this node

Title: {{input value=editedTitle}} From a44611a9b896513efcdad40a75421fe8ca9776e6 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Tue, 10 May 2016 13:28:43 -0400 Subject: [PATCH 080/959] add more registration work --- addon/models/institution.js | 10 +++++----- addon/models/user.js | 4 +++- addon/nodes/adapter.js | 4 ++++ app/nodes/adapter.js | 1 + tests/dummy/app/routes/registrations.js | 16 ++++++++++++++++ .../app/templates/institutions/detail.hbs | 4 ++-- .../dummy/app/templates/institutions/index.hbs | 4 ++-- tests/dummy/app/templates/registrations.hbs | 1 + .../app/templates/registrations/detail.hbs | 18 ++++++++++++++++++ .../app/templates/registrations/index.hbs | 15 +++++++++++++++ tests/unit/nodes/adapter-test.js | 12 ++++++++++++ 11 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 addon/nodes/adapter.js create mode 100644 app/nodes/adapter.js create mode 100644 tests/dummy/app/routes/registrations.js create mode 100644 tests/dummy/app/templates/registrations.hbs create mode 100644 tests/dummy/app/templates/registrations/detail.hbs create mode 100644 tests/dummy/app/templates/registrations/index.hbs create mode 100644 tests/unit/nodes/adapter-test.js diff --git a/addon/models/institution.js b/addon/models/institution.js index 7bd38ea87..f1f06ad27 100644 --- a/addon/models/institution.js +++ b/addon/models/institution.js @@ -5,17 +5,17 @@ import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ name: DS.attr('string'), description: DS.attr('string'), - logo_path: DS.attr('string'), - auth_url: DS.attr('string'), + logoPath: DS.attr('string'), + authUrl: DS.attr('string'), children: DS.hasMany('users', { - inverse: 'affiliated_institutions' + inverse: 'affiliatedInstitutions' }), nodes: DS.hasMany('nodes', { - inverse: 'affiliated_institutions' + inverse: 'affiliatedInstitutions' }), registrations: DS.hasMany('registrations', { - inverse: 'affiliated_institutions' + inverse: 'affiliatedInstitutions' }), }); diff --git a/addon/models/user.js b/addon/models/user.js index 7b54a50c0..b3a785bfe 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -8,8 +8,10 @@ export default OsfModel.extend({ family_name: DS.attr('string'), nodes: DS.hasMany('nodes'), + registrations: DS.hasMany('registrations'), - affiliated_institutions: DS.hasMany('institutions', { + affiliatedInstitutions: DS.hasMany('institutions', { inverse: 'users' }), + }); diff --git a/addon/nodes/adapter.js b/addon/nodes/adapter.js new file mode 100644 index 000000000..03e214724 --- /dev/null +++ b/addon/nodes/adapter.js @@ -0,0 +1,4 @@ +import JSONAPIAdapter from 'ember-data/adapters/json-api'; + +export default JSONAPIAdapter.extend({ +}); diff --git a/app/nodes/adapter.js b/app/nodes/adapter.js new file mode 100644 index 000000000..c3141d698 --- /dev/null +++ b/app/nodes/adapter.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/nodes/adapter'; diff --git a/tests/dummy/app/routes/registrations.js b/tests/dummy/app/routes/registrations.js new file mode 100644 index 000000000..ed07c46c2 --- /dev/null +++ b/tests/dummy/app/routes/registrations.js @@ -0,0 +1,16 @@ +import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default Ember.Route.extend(AuthenticatedRouteMixin, { + store: Ember.inject.service(), + session: Ember.inject.service(), + model() { + let user = this.modelFor('application'); + if(user) { + return user.get('registrations'); + } + else { + return this.get('store').findRecord('user', 'me').then(user => user.get('registrations')); + } + } +}); diff --git a/tests/dummy/app/templates/institutions/detail.hbs b/tests/dummy/app/templates/institutions/detail.hbs index 5fb539e02..824d8b869 100644 --- a/tests/dummy/app/templates/institutions/detail.hbs +++ b/tests/dummy/app/templates/institutions/detail.hbs @@ -2,8 +2,8 @@

{{model.name}}

{{model.description}}

-

{{model.logo_url}}

-

{{model.auth_url}}

+

{{model.logoPath}}

+

{{model.authUrl}}

View on OSF diff --git a/tests/dummy/app/templates/institutions/index.hbs b/tests/dummy/app/templates/institutions/index.hbs index 90e2fb573..1cb38ca8b 100644 --- a/tests/dummy/app/templates/institutions/index.hbs +++ b/tests/dummy/app/templates/institutions/index.hbs @@ -4,8 +4,8 @@

{{inst.name}}

{{inst.description}}

-

{{inst.logo_url}}

-

{{inst.auth_url}}

+

{{inst.logoPath}}

+

{{inst.authUrl}}

View on OSF diff --git a/tests/dummy/app/templates/registrations.hbs b/tests/dummy/app/templates/registrations.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/tests/dummy/app/templates/registrations.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/tests/dummy/app/templates/registrations/detail.hbs b/tests/dummy/app/templates/registrations/detail.hbs new file mode 100644 index 000000000..053deaa1a --- /dev/null +++ b/tests/dummy/app/templates/registrations/detail.hbs @@ -0,0 +1,18 @@ +{{link-to 'Back to list' 'registrations' class="btn btn-default"}} +

+

{{model.title}}

+

{{model.category}}

+

{{moment-format model.dateRegistered}}

+

+ + View on OSF + +

+ + + + +

{{link-to 'Node Registered' 'nodes.detail' model.registeredFrom.id class="btn btn-warning"}} +

+ +
diff --git a/tests/dummy/app/templates/registrations/index.hbs b/tests/dummy/app/templates/registrations/index.hbs new file mode 100644 index 000000000..352db559a --- /dev/null +++ b/tests/dummy/app/templates/registrations/index.hbs @@ -0,0 +1,15 @@ +

My Registrations

+{{#each model as |registration|}} +
+
+

{{registration.title}}

+

{{registration.category}}

+

{{moment-format registration.dateRegistered}}

+

+ + View on OSF + + {{link-to 'Detail' 'registrations.detail' registration.id class="btn btn-primary"}} +

+
+{{/each}} diff --git a/tests/unit/nodes/adapter-test.js b/tests/unit/nodes/adapter-test.js new file mode 100644 index 000000000..c350940e1 --- /dev/null +++ b/tests/unit/nodes/adapter-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:nodes', 'Unit | Adapter | nodes', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); From 1ab394b4df244acebf1151cd229de0d0ccc93936 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Tue, 10 May 2016 15:52:18 -0400 Subject: [PATCH 081/959] more registration wokr mend --- tests/dummy/app/routes/registrations/detail.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/dummy/app/routes/registrations/detail.js diff --git a/tests/dummy/app/routes/registrations/detail.js b/tests/dummy/app/routes/registrations/detail.js new file mode 100644 index 000000000..9dfedd003 --- /dev/null +++ b/tests/dummy/app/routes/registrations/detail.js @@ -0,0 +1,16 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model(params) { + return this.store.findRecord('registration', params.registration_id); + }, + afterModel: function(model){ + debugger; + + model.get('registeredFrom').then(function(resp){ + debugger; + }) + + return this.get('store') + } +}); From 03040fabcba3eeb044a31e234475e84ca55534c4 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 11 May 2016 16:10:11 -0400 Subject: [PATCH 082/959] remove unused afterModel --- tests/dummy/app/routes/registrations/detail.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/dummy/app/routes/registrations/detail.js b/tests/dummy/app/routes/registrations/detail.js index 9dfedd003..6f1415a30 100644 --- a/tests/dummy/app/routes/registrations/detail.js +++ b/tests/dummy/app/routes/registrations/detail.js @@ -3,14 +3,5 @@ import Ember from 'ember'; export default Ember.Route.extend({ model(params) { return this.store.findRecord('registration', params.registration_id); - }, - afterModel: function(model){ - debugger; - - model.get('registeredFrom').then(function(resp){ - debugger; - }) - - return this.get('store') } }); From d6d67365667d86d1b323fa6f491ceb2cf8951295 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 11 May 2016 16:31:36 -0400 Subject: [PATCH 083/959] clean-up --- addon/models/registration.js | 2 +- index.js | 1 - tests/dummy/app/router.js | 2 -- tests/dummy/app/templates/institutions.hbs | 2 +- tests/dummy/app/templates/nodes/detail.hbs | 2 ++ 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/addon/models/registration.js b/addon/models/registration.js index c8e84ab90..064b42dfc 100644 --- a/addon/models/registration.js +++ b/addon/models/registration.js @@ -36,6 +36,6 @@ export default OsfModel.extend({ registeredBy: DS.belongsTo('user'), contributors: DS.hasMany('contributors'), comments: DS.hasMany('comments'), - //more relationship + //more relationship }); diff --git a/index.js b/index.js index 8e8ea7af1..7e1e5c9f5 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,6 @@ module.exports = { return path.join(__dirname, 'blueprints'); }, config: function(environment, ENV) { - let BACKEND = process.env.BACKEND || 'local'; let SETTINGS = {}; try { diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 76b5e4825..28fe4a368 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -6,7 +6,6 @@ const Router = Ember.Router.extend({ }); Router.map(function() { - this.route('index', {path: '/'}); this.route('nodes', function() { this.route('detail', {path: '/:node_id'}); @@ -18,7 +17,6 @@ Router.map(function() { this.route('registrations', function() { this.route('detail', {path: '/:registration_id'}) }); - }); export default Router; diff --git a/tests/dummy/app/templates/institutions.hbs b/tests/dummy/app/templates/institutions.hbs index c24cd6895..f1b26897c 100644 --- a/tests/dummy/app/templates/institutions.hbs +++ b/tests/dummy/app/templates/institutions.hbs @@ -1 +1 @@ -{{outlet}} +{{focusing-outlet}} diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index db6f34f89..ed187c12d 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -28,6 +28,8 @@ {{/each}} + +

Edit this node

Title: {{input value=editedTitle}} From 7b5bc3fbb185b65396867a0fb1d1c0a1e3fc456a Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 11 May 2016 16:35:01 -0400 Subject: [PATCH 084/959] re add keyForRelationship and remove view on osf inst --- addon/serializers/application.js | 9 ++++++--- tests/dummy/app/templates/institutions/detail.hbs | 5 ----- tests/dummy/app/templates/registrations/detail.hbs | 5 +---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 89ab966f3..0d4309827 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -2,7 +2,7 @@ import Ember from 'ember'; import DS from 'ember-data'; export default DS.JSONAPISerializer.extend({ - + // TODO: Pre-1.0, refactor this into a separate OSF serializer, so we can support other microservices such as WB attrs: { links: {serialize: false}, @@ -19,7 +19,7 @@ export default DS.JSONAPISerializer.extend({ } return resourceHash; }, - + extractAttributes(modelClass, resourceHash) { resourceHash = this._mergeFields(resourceHash); return this._super(modelClass, resourceHash); @@ -32,7 +32,10 @@ export default DS.JSONAPISerializer.extend({ return Ember.String.camelize(key); } }, - + keyForRelationship(key) { + return Ember.String.underscore(key); + }, + serialize: function(snapshot, options) { var serialized = this._super(snapshot, options); // Don't send relationships to the server; this can lead to 500 errors. diff --git a/tests/dummy/app/templates/institutions/detail.hbs b/tests/dummy/app/templates/institutions/detail.hbs index 824d8b869..a9cf6102e 100644 --- a/tests/dummy/app/templates/institutions/detail.hbs +++ b/tests/dummy/app/templates/institutions/detail.hbs @@ -4,11 +4,6 @@

{{model.description}}

{{model.logoPath}}

{{model.authUrl}}

-

- - View on OSF - -


diff --git a/tests/dummy/app/templates/registrations/detail.hbs b/tests/dummy/app/templates/registrations/detail.hbs index 053deaa1a..263ab9fc9 100644 --- a/tests/dummy/app/templates/registrations/detail.hbs +++ b/tests/dummy/app/templates/registrations/detail.hbs @@ -8,10 +8,7 @@ View on OSF

- - - - +

{{link-to 'Node Registered' 'nodes.detail' model.registeredFrom.id class="btn btn-warning"}}

From 293e9417799b88a8ff3529616eb94480cf0d277e Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 11 May 2016 10:40:41 -0400 Subject: [PATCH 085/959] add node works --- tests/dummy/app/controllers/nodes/index.js | 14 ++++++++++++++ tests/dummy/app/templates/nodes/index.hbs | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/dummy/app/controllers/nodes/index.js diff --git a/tests/dummy/app/controllers/nodes/index.js b/tests/dummy/app/controllers/nodes/index.js new file mode 100644 index 000000000..58e213125 --- /dev/null +++ b/tests/dummy/app/controllers/nodes/index.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + actions:{ + createNode: function(title, description){ + var node = this.store.createRecord('node', { + title: title, + category: 'project', + description: description || null, + }) + node.save() + } + } +}); diff --git a/tests/dummy/app/templates/nodes/index.hbs b/tests/dummy/app/templates/nodes/index.hbs index 3926175a0..3073e9117 100644 --- a/tests/dummy/app/templates/nodes/index.hbs +++ b/tests/dummy/app/templates/nodes/index.hbs @@ -1,5 +1,15 @@

My Nodes

+ +
+ + {{input type="text" value=title placeholder="Node's title" required=true}} + + {{input type="text" value=description placeholder="Node's description"}} +

+
+ + From 107e4bef7da99d350cf75251836396b05d87c975 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 11 May 2016 16:43:05 -0400 Subject: [PATCH 086/959] clean up --- tests/dummy/app/templates/nodes/index.hbs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/dummy/app/templates/nodes/index.hbs b/tests/dummy/app/templates/nodes/index.hbs index 3073e9117..42c810a25 100644 --- a/tests/dummy/app/templates/nodes/index.hbs +++ b/tests/dummy/app/templates/nodes/index.hbs @@ -2,17 +2,14 @@
- - {{input type="text" value=title placeholder="Node's title" required=true}} - - {{input type="text" value=description placeholder="Node's description"}} -

+ + {{input type="text" value=title placeholder="Node's title" required=true}} + + {{input type="text" value=description placeholder="Node's description"}} +

- - - {{#each model as |node|}}
From 2bd2a7fcfb537a2cfa200eb0ad45892ec9e1ac10 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 11 May 2016 16:44:45 -0400 Subject: [PATCH 087/959] add affiliated_institutions view --- tests/dummy/app/templates/nodes/detail.hbs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index ed187c12d..a5308eccf 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -13,6 +13,10 @@


+

Edit this node

+ Title: {{input value=editedTitle}} + +

Contributors

@@ -28,10 +32,14 @@ {{/each}}
- - -

Edit this node

- Title: {{input value=editedTitle}} - - + +

+ + {{#each model.affiliatedInstitutions as |inst|}} + + {{inst.name}} + + {{/each}} +
+

From 0cc9a43549f1d8f1b6160ed811e2c4de3aaae704 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 11 May 2016 16:45:40 -0400 Subject: [PATCH 088/959] fix jshint --- tests/dummy/app/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 28fe4a368..b0169b11e 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -15,7 +15,7 @@ Router.map(function() { this.route('detail', {path: '/:institution_id'}); }); this.route('registrations', function() { - this.route('detail', {path: '/:registration_id'}) + this.route('detail', {path: '/:registration_id'}); }); }); From 16a5fcfdc2565cc2777c4aaf5d2425d32c92b4e3 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Wed, 11 May 2016 14:00:34 -0400 Subject: [PATCH 089/959] Add users and user detail routes Conflicts: tests/dummy/app/router.js --- addon/models/user.js | 1 + tests/dummy/app/router.js | 3 +++ tests/dummy/app/routes/users.js | 10 ++++++++++ tests/dummy/app/routes/users/detail.js | 4 ++++ tests/dummy/app/templates/index.hbs | 1 + tests/dummy/app/templates/users.hbs | 1 + tests/dummy/app/templates/users/detail.hbs | 1 + tests/dummy/app/templates/users/index.hbs | 15 +++++++++++++++ 8 files changed, 36 insertions(+) create mode 100644 tests/dummy/app/routes/users.js create mode 100644 tests/dummy/app/routes/users/detail.js create mode 100644 tests/dummy/app/templates/users.hbs create mode 100644 tests/dummy/app/templates/users/detail.hbs create mode 100644 tests/dummy/app/templates/users/index.hbs diff --git a/addon/models/user.js b/addon/models/user.js index 0076a5c79..e349f8da5 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -3,6 +3,7 @@ import DS from 'ember-data'; import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ + full_name: DS.attr('string'), given_name: DS.attr('string'), middle_names: DS.attr(), family_name: DS.attr('string'), diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index dc7d751eb..25fad1a97 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -11,6 +11,9 @@ Router.map(function() { this.route('detail', {path: '/:node_id'}); }); this.route('login'); + this.route('users', function() { + this.route('detail', {path: '/:user_id'}); + }); }); export default Router; diff --git a/tests/dummy/app/routes/users.js b/tests/dummy/app/routes/users.js new file mode 100644 index 000000000..15c1636ee --- /dev/null +++ b/tests/dummy/app/routes/users.js @@ -0,0 +1,10 @@ +import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default Ember.Route.extend(AuthenticatedRouteMixin, { + store: Ember.inject.service(), + session: Ember.inject.service(), + model() { + return this.get('store').findAll('user'); + } +}); diff --git a/tests/dummy/app/routes/users/detail.js b/tests/dummy/app/routes/users/detail.js new file mode 100644 index 000000000..26d9f3124 --- /dev/null +++ b/tests/dummy/app/routes/users/detail.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ +}); diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs index 40bbcc845..4fbb924d1 100644 --- a/tests/dummy/app/templates/index.hbs +++ b/tests/dummy/app/templates/index.hbs @@ -1 +1,2 @@ {{link-to 'My Nodes' 'nodes' class="btn btn-default"}} +{{link-to 'Users' 'users' class="btn btn-default"}} \ No newline at end of file diff --git a/tests/dummy/app/templates/users.hbs b/tests/dummy/app/templates/users.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/tests/dummy/app/templates/users.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/tests/dummy/app/templates/users/detail.hbs b/tests/dummy/app/templates/users/detail.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/tests/dummy/app/templates/users/detail.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/tests/dummy/app/templates/users/index.hbs b/tests/dummy/app/templates/users/index.hbs new file mode 100644 index 000000000..4a38e7165 --- /dev/null +++ b/tests/dummy/app/templates/users/index.hbs @@ -0,0 +1,15 @@ +

Users

+
+{{#each model as |user|}} +
+

{{user.full_name}}

+

{{moment-format user.date_registered}}

+
+

+ + View on OSF + + {{link-to 'Detail' 'users.detail' user.id class="btn btn-primary"}} +

+
+{{/each}} \ No newline at end of file From 3e245c099f2b5b852af876c40793bc81bbd6692d Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Wed, 11 May 2016 14:36:57 -0400 Subject: [PATCH 090/959] Add user detail info --- tests/dummy/app/routes/users/detail.js | 3 +++ tests/dummy/app/templates/users/detail.hbs | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/dummy/app/routes/users/detail.js b/tests/dummy/app/routes/users/detail.js index 26d9f3124..762ec37af 100644 --- a/tests/dummy/app/routes/users/detail.js +++ b/tests/dummy/app/routes/users/detail.js @@ -1,4 +1,7 @@ import Ember from 'ember'; export default Ember.Route.extend({ + model(params) { + return this.store.findRecord('user', params.user_id); + } }); diff --git a/tests/dummy/app/templates/users/detail.hbs b/tests/dummy/app/templates/users/detail.hbs index c24cd6895..7ccb3d0d3 100644 --- a/tests/dummy/app/templates/users/detail.hbs +++ b/tests/dummy/app/templates/users/detail.hbs @@ -1 +1,11 @@ -{{outlet}} +{{link-to 'Back to list' 'users' class="btn btn-default"}} +
+

{{model.full_name}}

+

{{moment-format model.date_registered}}

+

+ + View on OSF + +

+
+
From 5ee0b7286774193b376779720cfb8c308a6bd633 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 11 May 2016 16:57:52 -0400 Subject: [PATCH 091/959] Add a file-tree component to demo files --- addon/models/file-provider.js | 2 + addon/models/file.js | 5 +- tests/dummy/app/components/file-tree.js | 6 ++ tests/dummy/app/router.js | 4 +- tests/dummy/app/routes/nodes/detail/files.js | 6 -- .../app/templates/components/file-tree.hbs | 10 +++ tests/dummy/app/templates/nodes/detail.hbs | 48 +++++++++++++- .../app/templates/nodes/detail/files.hbs | 8 --- .../app/templates/nodes/detail/index.hbs | 63 ------------------- 9 files changed, 70 insertions(+), 82 deletions(-) create mode 100644 tests/dummy/app/components/file-tree.js delete mode 100644 tests/dummy/app/routes/nodes/detail/files.js create mode 100644 tests/dummy/app/templates/components/file-tree.hbs delete mode 100644 tests/dummy/app/templates/nodes/detail/files.hbs delete mode 100644 tests/dummy/app/templates/nodes/detail/index.hbs diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index a8d4ac2ea..ed2343a0a 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -9,4 +9,6 @@ export default OsfModel.extend({ //node: DS.belongsTo('node'), provider: DS.attr('string'), files: DS.hasMany('file'), + + isFolder: Ember.computed.equal('kind', 'folder'), }); diff --git a/addon/models/file.js b/addon/models/file.js index 4fcaad6b8..9be332f0d 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -23,5 +23,8 @@ export default OsfModel.extend({ // File attributes versions: DS.hasMany('file-version'), comments: DS.hasMany('comment'), - contents: DS.belongsTo('file-contents') + contents: DS.belongsTo('file-contents'), + + + isFolder: Ember.computed.equal('kind', 'folder'), }); diff --git a/tests/dummy/app/components/file-tree.js b/tests/dummy/app/components/file-tree.js new file mode 100644 index 000000000..8311e31bc --- /dev/null +++ b/tests/dummy/app/components/file-tree.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; +import layout from '../templates/components/file-tree'; + +export default Ember.Component.extend({ + layout +}); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index cddbcee97..dc7d751eb 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -8,9 +8,7 @@ const Router = Ember.Router.extend({ Router.map(function() { this.route('index', {path: '/'}); this.route('nodes', function() { - this.route('detail', {path: '/:node_id'}, function() { - this.route('files'); - }); + this.route('detail', {path: '/:node_id'}); }); this.route('login'); }); diff --git a/tests/dummy/app/routes/nodes/detail/files.js b/tests/dummy/app/routes/nodes/detail/files.js deleted file mode 100644 index cdf1f982b..000000000 --- a/tests/dummy/app/routes/nodes/detail/files.js +++ /dev/null @@ -1,6 +0,0 @@ -import Ember from 'ember'; - -export default Ember.Route.extend({ - //afterModel(model) { - //} -}); diff --git a/tests/dummy/app/templates/components/file-tree.hbs b/tests/dummy/app/templates/components/file-tree.hbs new file mode 100644 index 000000000..4b2615076 --- /dev/null +++ b/tests/dummy/app/templates/components/file-tree.hbs @@ -0,0 +1,10 @@ +
+ (kind:{{model.kind}} path:{{model.path}}) + {{#if model.isFolder}} +
+ {{#each model.files as |file|}} + {{file-tree model=file}} + {{/each}} +
+ {{/if}} +
diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index e2147cab0..775db6aa5 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -1 +1,47 @@ -{{outlet}} \ No newline at end of file +{{link-to 'Back to list' 'nodes' class="btn btn-default"}} +
+ +

Data

+

{{model.title}}

+

{{model.category}}

+

{{moment-format model.dateCreated}}

+

{{moment-format model.dateModified}}

+

+ + View on OSF + +

+
+ +

Contributors

+ + + + + + + {{#each model.contributors as |contrib|}} + + + + + {{/each}} +
IDAuthor?
{{contrib.id}}{{contrib.bibliographic}}
+ + + +

Edit this node

+ Title: {{input value=editedTitle}} + + +
+ +

Files

+
+ {{#each model.files as |provider|}} + {{file-tree model=provider}} + {{/each}} +
+
+ +{{outlet}} diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs deleted file mode 100644 index 94ce0cd5a..000000000 --- a/tests/dummy/app/templates/nodes/detail/files.hbs +++ /dev/null @@ -1,8 +0,0 @@ -{{link-to 'Back to node' 'nodes.detail' model class="btn btn-default"}} -
-{{#each model.files as |provider|}} -

{{provider.name}}

-

{{provider.kind}}

-

{{provider.path}}

-{{/each}} -
diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs deleted file mode 100644 index 5c58f6eee..000000000 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ /dev/null @@ -1,63 +0,0 @@ -{{link-to 'Back to list' 'nodes' class="btn btn-default"}} -
- -

Data

-

{{model.title}}

-

{{model.category}}

-

{{moment-format model.dateCreated}}

-

{{moment-format model.dateModified}}

-

- - View on OSF - -

-
- -

Contributors

- - - - - - - {{#each model.contributors as |contrib|}} - - - - - {{/each}} -
IDAuthor?
{{contrib.id}}{{contrib.bibliographic}}
- - - -

Edit this node

- Title: {{input value=editedTitle}} - - -
- -

File Providers

- - - - - - - - - {{#each model.files as |provider|}} - - - - - - - {{/each}} -
NameKindPathFilenames
{{provider.name}}{{provider.kind}}{{provider.path}} - {{#each provider.files as |file|}} -

{{file.name}}

- {{/each}} -
-
- -{{outlet}} From 33894c426e3b7b9c608541d983ddeefdfccdfd6e Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 17:08:09 -0400 Subject: [PATCH 092/959] Fix relationships and some reformatting null reflexive inverses are possible: https://guides.emberjs.com/v2.4.0/models/relationships/#toc_reflexive-relations --- addon/models/comment.js | 4 +++- addon/models/node.js | 4 +++- tests/dummy/app/controllers/nodes/index.js | 18 +++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/addon/models/comment.js b/addon/models/comment.js index 3e082627e..8d66f104d 100644 --- a/addon/models/comment.js +++ b/addon/models/comment.js @@ -12,7 +12,9 @@ export default OsfModel.extend({ //target TargetField(link_type='related', meta={'type': 'get_target_type'}) user: DS.belongsTo('user'), node: DS.belongsTo('node'), - replies: DS.hasMany('comment'), + replies: DS.hasMany('comment', { + inverse: null + }), //reports: DS.hasMany('comment-report'), diff --git a/addon/models/node.js b/addon/models/node.js index df7e0778e..fba31b13b 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -35,6 +35,8 @@ export default OsfModel.extend({ //nodeLinks: DS.hasMany('node-pointers'), //registrations: DS.hasMany('registrations'), //primaryInstitution: DS.belongsTo('institution'), - root: DS.belongsTo('node') + root: DS.belongsTo('node', { + inverse: null + }) //logs: DS.hasMany('node-logs'), }); diff --git a/tests/dummy/app/controllers/nodes/index.js b/tests/dummy/app/controllers/nodes/index.js index 58e213125..634651ce4 100644 --- a/tests/dummy/app/controllers/nodes/index.js +++ b/tests/dummy/app/controllers/nodes/index.js @@ -1,14 +1,14 @@ import Ember from 'ember'; export default Ember.Controller.extend({ - actions:{ - createNode: function(title, description){ - var node = this.store.createRecord('node', { - title: title, - category: 'project', - description: description || null, - }) - node.save() + actions: { + createNode: function(title, description) { + var node = this.store.createRecord('node', { + title: title, + category: 'project', + description: description || null + }); + node.save(); + } } - } }); From 7f0902789991356b1db9134d4e7f2826f8e3907e Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 11 May 2016 17:21:51 -0400 Subject: [PATCH 093/959] Hide file tree on dummy page --- tests/dummy/app/router.js | 4 +++- tests/dummy/app/routes/nodes/detail/files.js | 4 ++++ tests/dummy/app/templates/components/file-tree.hbs | 2 +- tests/dummy/app/templates/nodes/detail.hbs | 8 ++------ tests/dummy/app/templates/nodes/detail/files.hbs | 5 +++++ 5 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 tests/dummy/app/routes/nodes/detail/files.js create mode 100644 tests/dummy/app/templates/nodes/detail/files.hbs diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index dc7d751eb..8c16c567d 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -8,7 +8,9 @@ const Router = Ember.Router.extend({ Router.map(function() { this.route('index', {path: '/'}); this.route('nodes', function() { - this.route('detail', {path: '/:node_id'}); + this.route('detail', {path: '/:node_id'}, function() { + this.route('files'); + }); }); this.route('login'); }); diff --git a/tests/dummy/app/routes/nodes/detail/files.js b/tests/dummy/app/routes/nodes/detail/files.js new file mode 100644 index 000000000..26d9f3124 --- /dev/null +++ b/tests/dummy/app/routes/nodes/detail/files.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ +}); diff --git a/tests/dummy/app/templates/components/file-tree.hbs b/tests/dummy/app/templates/components/file-tree.hbs index 4b2615076..bbeaba6d7 100644 --- a/tests/dummy/app/templates/components/file-tree.hbs +++ b/tests/dummy/app/templates/components/file-tree.hbs @@ -1,5 +1,5 @@
- (kind:{{model.kind}} path:{{model.path}}) + {{#if model.isFolder}}
{{#each model.files as |file|}} diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 775db6aa5..9769fbc71 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -36,12 +36,8 @@
-

Files

-
- {{#each model.files as |provider|}} - {{file-tree model=provider}} - {{/each}} -
+

Files

+ {{link-to 'Show File Tree' 'nodes.detail.files' model.id}}
{{outlet}} diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs new file mode 100644 index 000000000..f0474048b --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/files.hbs @@ -0,0 +1,5 @@ +
+ {{#each model.files as |provider|}} + {{file-tree model=provider}} + {{/each}} +
From 5c693c877456ca9506f6ede1db4c7adccb3763b5 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 18:09:14 -0400 Subject: [PATCH 094/959] Use jscs to check code style - fix all of the errors - add to travis build chain - update CONTRIBUTING.md --- .github/CONTRIBUTING.md | 5 ++ .travis.yml | 2 +- addon/authenticators/osf-token.js | 6 +- addon/models/base.js | 2 +- addon/models/comment.js | 8 +- addon/models/contributor.js | 2 +- addon/models/institution.js | 2 +- addon/models/node.js | 4 +- addon/models/registration.js | 4 +- addon/serializers/application.js | 18 ++-- config/environment.js | 2 +- ember-cli-build.js | 4 +- index.js | 4 +- package.json | 141 ++++++++++++++++-------------- tests/dummy/app/app.js | 6 +- tests/dummy/app/router.js | 16 +++- tests/dummy/config/environment.js | 12 +-- 17 files changed, 134 insertions(+), 104 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index eff1ff826..8230e85c4 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,5 +1,10 @@ # Style/Conventions +### Checking your code + +Code style checking is part of the Travis build, and PRs that do not meet the code style guidelines will not be merged. You can run these checks locally with: +`npm run check-style` + ### Naming conventions Please review and adhere to the naming conventions defined [here](http://ember-cli.com/user-guide/#naming-conventions) diff --git a/.travis.yml b/.travis.yml index 02533c978..383160a89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,4 +20,4 @@ install: - bower install script: - - npm test + - npm run check-style && npm test diff --git a/addon/authenticators/osf-token.js b/addon/authenticators/osf-token.js index 9727ff8a4..9e8e100be 100644 --- a/addon/authenticators/osf-token.js +++ b/addon/authenticators/osf-token.js @@ -6,13 +6,15 @@ import config from 'ember-get-config'; export default BaseAuthenticator.extend({ store: Ember.inject.service(), authUrl: `${config.OSF.authUrl}/`, - _test (accessToken) { + _test(accessToken) { return Ember.$.ajax({ method: 'GET', url: `${config.OSF.apiUrl}/${config.OSF.apiNamespace}/users/me/`, dataType: 'json', contentType: 'application/json', - xhrFields: {withCredentials: false}, + xhrFields: { + withCredentials: false + }, headers: { Authorization: `Bearer ${accessToken}` } diff --git a/addon/models/base.js b/addon/models/base.js index ab2133a26..67a215787 100644 --- a/addon/models/base.js +++ b/addon/models/base.js @@ -2,5 +2,5 @@ import DS from 'ember-data'; export default DS.Model.extend({ links: DS.attr('links'), - embeds: DS.attr('embed') + embeds: DS.attr('embed') }); diff --git a/addon/models/comment.js b/addon/models/comment.js index 8d66f104d..b1d5e4850 100644 --- a/addon/models/comment.js +++ b/addon/models/comment.js @@ -13,16 +13,16 @@ export default OsfModel.extend({ user: DS.belongsTo('user'), node: DS.belongsTo('node'), replies: DS.hasMany('comment', { - inverse: null + inverse: null }), - + //reports: DS.hasMany('comment-report'), - + dateCreated: DS.attr('date'), dateModified: DS.attr('date'), modified: DS.attr('boolean'), deleted: DS.attr('boolean'), isAbuse: DS.attr('boolean'), hasChildren: DS.attr('boolean'), - canEdit: DS.attr('boolean') + canEdit: DS.attr('boolean') }); diff --git a/addon/models/contributor.js b/addon/models/contributor.js index 43a6fe84c..b452976e5 100644 --- a/addon/models/contributor.js +++ b/addon/models/contributor.js @@ -5,5 +5,5 @@ import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ bibliographic: DS.attr('boolean'), permission: DS.attr('string'), - users: DS.hasMany('user') + users: DS.hasMany('user') }); diff --git a/addon/models/institution.js b/addon/models/institution.js index f1f06ad27..daa14ddf0 100644 --- a/addon/models/institution.js +++ b/addon/models/institution.js @@ -16,6 +16,6 @@ export default OsfModel.extend({ }), registrations: DS.hasMany('registrations', { inverse: 'affiliatedInstitutions' - }), + }) }); diff --git a/addon/models/node.js b/addon/models/node.js index 8d64e6459..f467c6013 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -37,11 +37,11 @@ export default OsfModel.extend({ //forkedFrom: DS.belongsTo('node'), //nodeLinks: DS.hasMany('node-pointers'), registrations: DS.hasMany('registrations', { - inverse: 'registeredFrom' + inverse: 'registeredFrom' }), root: DS.belongsTo('node', { - inverse: null + inverse: null }) //logs: DS.hasMany('node-logs'), }); diff --git a/addon/models/registration.js b/addon/models/registration.js index 064b42dfc..f9ff08f78 100644 --- a/addon/models/registration.js +++ b/addon/models/registration.js @@ -31,11 +31,11 @@ export default OsfModel.extend({ inverse: 'registrations' }), registeredFrom: DS.belongsTo('node', { - inverse: 'registrations' + inverse: 'registrations' }), registeredBy: DS.belongsTo('user'), contributors: DS.hasMany('contributors'), - comments: DS.hasMany('comments'), + comments: DS.hasMany('comments') //more relationship }); diff --git a/addon/serializers/application.js b/addon/serializers/application.js index 0d4309827..7ba903175 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/application.js @@ -5,18 +5,22 @@ export default DS.JSONAPISerializer.extend({ // TODO: Pre-1.0, refactor this into a separate OSF serializer, so we can support other microservices such as WB attrs: { - links: {serialize: false}, - embeds: {serialize: false} + links: { + serialize: false + }, + embeds: { + serialize: false + } }, _mergeFields(resourceHash) { // ApiV2 `links` exist outside the attributes field; make them accessible to the data model - if (resourceHash.links) { // TODO: Should also test whether model class defines a links field + if (resourceHash.links) { // TODO: Should also test whether model class defines a links field resourceHash.attributes.links = resourceHash.links; } - if (resourceHash.embeds) { - resourceHash.attributes.embeds = resourceHash.embeds; - } + if (resourceHash.embeds) { + resourceHash.attributes.embeds = resourceHash.embeds; + } return resourceHash; }, @@ -35,7 +39,7 @@ export default DS.JSONAPISerializer.extend({ keyForRelationship(key) { return Ember.String.underscore(key); }, - + serialize: function(snapshot, options) { var serialized = this._super(snapshot, options); // Don't send relationships to the server; this can lead to 500 errors. diff --git a/config/environment.js b/config/environment.js index 28a787b62..17c660f6a 100644 --- a/config/environment.js +++ b/config/environment.js @@ -2,5 +2,5 @@ 'use strict'; module.exports = function(/* environment, appConfig */) { - return { }; + return {}; }; diff --git a/ember-cli-build.js b/ember-cli-build.js index fce710214..77eb87914 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -3,9 +3,7 @@ var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { - var app = new EmberAddon(defaults, { - }); - + var app = new EmberAddon(defaults, {}); app.import('bower_components/bootstrap/dist/css/bootstrap.min.css'); app.import('bower_components/bootstrap/dist/css/bootstrap-theme.min.css'); diff --git a/index.js b/index.js index 7e1e5c9f5..c28960264 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ module.exports = { try { SETTINGS = config.get(BACKEND); } catch (e) { - console.log(`WARNING: you have specified a backend '${BACKEND}' that you have not configured in your config/local.yml`); + console.log(`WARNING: you\'ve specified a backend '${BACKEND}' that you have not configured in your config/local.yml`); } ENV.OSF = { @@ -47,7 +47,7 @@ module.exports = { ENV.OSF.authUrl = 'https://test-accounts.osf.io/oauth2/authorize'; } if (BACKEND === 'prod') { - console.log('WARNING: you\'ve specified production as a backend. Please do not use production for testing or development purposes'); + console.log(`WARNING: you\'ve specified production as a backend. Please do not use production for testing or development purposes`); ENV.OSF.url = 'https://osf.io/'; ENV.OSF.apiUrl = 'https://api.osf.io'; ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; diff --git a/package.json b/package.json index 07ab56a32..4f7fbfd8d 100644 --- a/package.json +++ b/package.json @@ -1,66 +1,79 @@ { - "name": "ember-osf", - "version": "0.0.1", - "description": "Ember Data models for the OSF APIv2", - "directories": { - "doc": "doc", - "test": "tests" - }, - "scripts": { - "build": "ember build", - "start": "ember server", - "test": "ember test" - }, - "repository": "", - "engines": { - "node": ">= 0.10.0" - }, - "author": "", - "license": "MIT", - "devDependencies": { - "broccoli-asset-rev": "^2.2.0", - "ember-a11y": "0.1.8", - "ember-a11y-testing": "0.0.5", - "ember-ajax": "0.7.1", - "ember-cli": "^2.4.3", - "ember-cli-app-version": "^1.0.0", - "ember-cli-dependency-checker": "^1.2.0", - "ember-cli-htmlbars": "^1.0.1", - "ember-cli-htmlbars-inline-precompile": "^0.3.1", - "ember-cli-inject-live-reload": "^1.3.1", - "ember-cli-mirage": "0.1.13", - "ember-cli-qunit": "^1.2.1", - "ember-cli-release": "0.2.8", - "ember-cli-sass": "5.3.1", - "ember-cli-sri": "^2.0.0", - "ember-cli-uglify": "^1.2.0", - "ember-data": "^2.3.0", - "ember-disable-prototype-extensions": "^1.0.0", - "ember-disable-proxy-controllers": "^1.0.1", - "ember-export-application-global": "^1.0.4", - "ember-i18n": "4.2.1", - "ember-load-initializers": "0.5.1", - "ember-resolver": "2.0.3", - "ember-sinon": "0.5.0", - "ember-sinon-qunit": "1.3.1", - "loader": "2.1.0", - "loader.js": "4.0.3", - "moment": "^2.13.0" - }, - "keywords": [ - "ember-addon" - ], - "dependencies": { - "config": "^1.20.1", - "ember-cli-babel": "^5.1.5", - "ember-cli-moment-shim": "1.1.0", - "ember-cli-node-assets": "^0.1.3", - "ember-get-config": "0.0.2", - "ember-moment": "6.1.0", - "ember-simple-auth": "1.1.0-beta.5", - "js-yaml": "^3.6.0" - }, - "ember-addon": { - "configPath": "tests/dummy/config" - } + "name": "ember-osf", + "version": "0.0.1", + "description": "Ember Data models for the OSF APIv2", + "directories": { + "doc": "doc", + "test": "tests" + }, + "scripts": { + "build": "ember build", + "start": "ember server", + "test": "ember test", + "check-style": "./node_modules/jscs/bin/jscs ." + }, + "repository": "", + "engines": { + "node": ">= 0.10.0" + }, + "author": "", + "license": "MIT", + "devDependencies": { + "broccoli-asset-rev": "^2.2.0", + "ember-a11y": "0.1.8", + "ember-a11y-testing": "0.0.5", + "ember-ajax": "0.7.1", + "ember-cli": "^2.4.3", + "ember-cli-app-version": "^1.0.0", + "ember-cli-dependency-checker": "^1.2.0", + "ember-cli-htmlbars": "^1.0.1", + "ember-cli-htmlbars-inline-precompile": "^0.3.1", + "ember-cli-inject-live-reload": "^1.3.1", + "ember-cli-mirage": "0.1.13", + "ember-cli-qunit": "^1.2.1", + "ember-cli-release": "0.2.8", + "ember-cli-sass": "5.3.1", + "ember-cli-sri": "^2.0.0", + "ember-cli-uglify": "^1.2.0", + "ember-data": "^2.3.0", + "ember-disable-prototype-extensions": "^1.0.0", + "ember-disable-proxy-controllers": "^1.0.1", + "ember-export-application-global": "^1.0.4", + "ember-i18n": "4.2.1", + "ember-load-initializers": "0.5.1", + "ember-resolver": "2.0.3", + "ember-sinon": "0.5.0", + "ember-sinon-qunit": "1.3.1", + "jscs": "^3.0.3", + "loader": "2.1.0", + "loader.js": "4.0.3", + "moment": "^2.13.0" + }, + "keywords": [ + "ember-addon" + ], + "dependencies": { + "config": "^1.20.1", + "ember-cli-babel": "^5.1.5", + "ember-cli-moment-shim": "1.1.0", + "ember-cli-node-assets": "^0.1.3", + "ember-get-config": "0.0.2", + "ember-moment": "6.1.0", + "ember-simple-auth": "1.1.0-beta.5", + "js-yaml": "^3.6.0" + }, + "ember-addon": { + "configPath": "tests/dummy/config" + }, + "jscsConfig": { + "preset": "airbnb", + "excludeFiles": ["bower_components", "dist", "tmp", "vendor", "app/locales", "tests"], + "requireSpacesInAnonymousFunctionExpression": false, + "requireTrailingComma": false, + "disallowTrailingComma": false, + "requirePaddingNewLinesAfterBlocks": false, + "validateIndentation": 4, + "requirePaddingNewLinesBeforeLineComments": false, + "maximumLineLength": false + } } diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index 831ad6106..f260c4c70 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -8,9 +8,9 @@ let App; Ember.MODEL_FACTORY_INJECTIONS = true; App = Ember.Application.extend({ - modulePrefix: config.modulePrefix, - podModulePrefix: config.podModulePrefix, - Resolver + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix, + Resolver }); loadInitializers(App, config.modulePrefix); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index b0169b11e..97e2e7975 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -6,16 +6,24 @@ const Router = Ember.Router.extend({ }); Router.map(function() { - this.route('index', {path: '/'}); + this.route('index', { + path: '/' + }); this.route('nodes', function() { - this.route('detail', {path: '/:node_id'}); + this.route('detail', { + path: '/:node_id' + }); }); this.route('login'); this.route('institutions', function() { - this.route('detail', {path: '/:institution_id'}); + this.route('detail', { + path: '/:institution_id' + }); }); this.route('registrations', function() { - this.route('detail', {path: '/:registration_id'}); + this.route('detail', { + path: '/:registration_id' + }); }); }); diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index a5827a8cd..ee8ecc20e 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -21,18 +21,18 @@ module.exports = function(environment) { authenticationRoute: 'login', routeAfterAuthentication: 'index' }, - 'ember-cli-mirage': { - enabled: false - } + 'ember-cli-mirage': { + enabled: false + } }; - if (environment === 'development') { + /*if (environment === 'development') { //ENV.APP.LOG_RESOLVER = true; //ENV.APP.LOG_ACTIVE_GENERATION = true; //ENV.APP.LOG_TRANSITIONS = true; //ENV.APP.LOG_TRANSITIONS_INTERNAL = true; //ENV.APP.LOG_VIEW_LOOKUPS = true; - } + }*/ if (environment === 'test') { // Testem prefers this... @@ -53,7 +53,7 @@ module.exports = function(environment) { ENV.APP.LOG_TRANSITIONS = true; } - if (environment === 'production') {} + //if (environment === 'production') {} return ENV; }; From a5276f5cc1e0f68c2fcf45cd8bea32d623dfd639 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 18:25:41 -0400 Subject: [PATCH 095/959] Add models tests dependencies - also fix User.affiliatedInstitutions relationship --- addon/models/user.js | 5 ++--- tests/unit/models/institution-test.js | 15 +++++++++------ tests/unit/models/node-test.js | 2 +- tests/unit/models/registration-test.js | 15 +++++++++------ tests/unit/models/user-test.js | 15 +++++++++------ 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/addon/models/user.js b/addon/models/user.js index b3a785bfe..33a8ed418 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -11,7 +11,6 @@ export default OsfModel.extend({ registrations: DS.hasMany('registrations'), affiliatedInstitutions: DS.hasMany('institutions', { - inverse: 'users' - }), - + inverse: 'children' + }) }); diff --git a/tests/unit/models/institution-test.js b/tests/unit/models/institution-test.js index 1857242b4..3cc22f68f 100644 --- a/tests/unit/models/institution-test.js +++ b/tests/unit/models/institution-test.js @@ -1,12 +1,15 @@ -import { moduleForModel, test } from 'ember-qunit'; +import { + moduleForModel, + test +} from 'ember-qunit'; moduleForModel('institution', 'Unit | Model | institution', { - // Specify the other units that are required for this test. - needs: [] + // Specify the other units that are required for this test. + needs: ['model:user', 'model:node', 'model:registration'] }); test('it exists', function(assert) { - let model = this.subject(); - // let store = this.store(); - assert.ok(!!model); + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); }); diff --git a/tests/unit/models/node-test.js b/tests/unit/models/node-test.js index bea4dac90..95aac5c75 100644 --- a/tests/unit/models/node-test.js +++ b/tests/unit/models/node-test.js @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('node', 'Unit | Model | node', { // Specify the other units that are required for this test. - needs: ['model:user', 'model:contributor', 'model:comment'] + needs: ['model:user', 'model:contributor', 'model:comment', 'model:institution', 'model:registration'] }); test('it exists', function(assert) { diff --git a/tests/unit/models/registration-test.js b/tests/unit/models/registration-test.js index 2b091c1ed..10567c730 100644 --- a/tests/unit/models/registration-test.js +++ b/tests/unit/models/registration-test.js @@ -1,12 +1,15 @@ -import { moduleForModel, test } from 'ember-qunit'; +import { + moduleForModel, + test +} from 'ember-qunit'; moduleForModel('registration', 'Unit | Model | registration', { - // Specify the other units that are required for this test. - needs: [] + // Specify the other units that are required for this test. + needs: ['model:institution', 'model:node', 'model:user', 'model:contributor', 'model:comment'] }); test('it exists', function(assert) { - let model = this.subject(); - // let store = this.store(); - assert.ok(!!model); + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); }); diff --git a/tests/unit/models/user-test.js b/tests/unit/models/user-test.js index 6f3440c80..94e942234 100644 --- a/tests/unit/models/user-test.js +++ b/tests/unit/models/user-test.js @@ -1,12 +1,15 @@ -import { moduleForModel, test } from 'ember-qunit'; +import { + moduleForModel, + test +} from 'ember-qunit'; moduleForModel('user', 'Unit | Model | user', { - // Specify the other units that are required for this test. - needs: ['model:node'] + // Specify the other units that are required for this test. + needs: ['model:node', 'model:institution', 'model:registration'] }); test('it exists', function(assert) { - let model = this.subject(); - // let store = this.store(); - assert.ok(!!model); + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); }); From a7b72686c41e911f32d38db374bac90d3e05b5b3 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 18:27:50 -0400 Subject: [PATCH 096/959] Let Registration model subclass Node --- addon/models/registration.js | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/addon/models/registration.js b/addon/models/registration.js index f9ff08f78..28ad9142a 100644 --- a/addon/models/registration.js +++ b/addon/models/registration.js @@ -1,22 +1,10 @@ import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import Node from 'ember-osf/models/node'; -export default OsfModel.extend({ - title: DS.attr('string'), - registration: DS.attr('boolean'), - public: DS.attr('boolean'), - category: DS.attr('string'), - fork: DS.attr('boolean'), - description: DS.attr('string'), - collection: DS.attr('boolean'), - - dateCreated: DS.attr('date'), - dateModified: DS.attr('date'), +export default Node.extend({ dateRegistered: DS.attr('date'), - pendingRegistrationApproval: DS.attr('boolean'), - embargoEndDate: DS.attr('date'), pendingEmbargoApproval: DS.attr('boolean'), withdrawn: DS.attr('boolean'), @@ -25,17 +13,14 @@ export default OsfModel.extend({ registrationSupplement: DS.attr('string'), registeredMeta: DS.attr(), - tags: DS.attr(), - affiliatedInstitutions: DS.hasMany('institutions', { - inverse: 'registrations' - }), registeredFrom: DS.belongsTo('node', { inverse: 'registrations' }), - registeredBy: DS.belongsTo('user'), + registeredBy: DS.belongsTo('user', { + inverse: null + }), contributors: DS.hasMany('contributors'), comments: DS.hasMany('comments') //more relationship - }); From e8a090ee0478d3d952fbd670afffa982e1808924 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 18:40:18 -0400 Subject: [PATCH 097/959] Use test for development --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7d80714e5..c5f2dd5af 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,9 @@ Edit the new file (installed in the config directory) and set: - `CLIENT_ID` to the client id of your developer application - `PERSONAL_ACCESS_TOKEN` to the newly generated token (if applicable, optional for staging development) -#### Using the Staging or Test API +#### Using the Test API -To do this, you will need to [create a developer application](https://staging.osf.io/settings/applications/) on the relevant version of the OSF. +To do this, you will need to [create a developer application](https://test.osf.io/settings/applications/) on the relevant version of the OSF. #### Running the OSF Locally (optional) @@ -89,7 +89,7 @@ Other options include: - staging (`stage`): contains bleeding edge features, but less stable - staging2 (`stage2`): another version of staging using running a specific feature branch -Then (using staging as an example) run: +Then (using test as an example) run: `BACKEND=test ember server` and visit your app at http://localhost:4200. From a232cd8b4db3b78deb75f33938bfecae1bf3e8a6 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 11 May 2016 18:43:20 -0400 Subject: [PATCH 098/959] Add note to README addresses https://github.com/CenterForOpenScience/ember-osf/issues/4#issuecomment-218570749 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7d80714e5..0c7df98e2 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ Please read the [CONTRIBUTING.md](https://github.com/CenterForOpenScience/ember- export default Ember.Route.extend(OsfLoginRouteMixin); ``` +> **Note**: Running ember install will automatically install all bower and npm dependencies for ember-osf. + ## Configuration #### local.yml settings From 2762d83cb9a768a0993c8a7438a098de5fe57d9a Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 12 May 2016 09:32:21 -0400 Subject: [PATCH 099/959] Add missing imports --- addon/models/file-provider.js | 1 + addon/models/file.js | 1 + 2 files changed, 2 insertions(+) diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index ed2343a0a..8d926d9b7 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -1,3 +1,4 @@ +import Ember from 'ember'; import DS from 'ember-data'; import OsfModel from 'ember-osf/models/base'; diff --git a/addon/models/file.js b/addon/models/file.js index 9be332f0d..4dfdf8364 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -1,3 +1,4 @@ +import Ember from 'ember'; import DS from 'ember-data'; import OsfModel from 'ember-osf/models/base'; From ddaf37266463eefc2c9efa9f7129c90ae3a55b0e Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 12 May 2016 09:53:18 -0400 Subject: [PATCH 100/959] CamelCase user model fields --- addon/models/user.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addon/models/user.js b/addon/models/user.js index e349f8da5..186761332 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -3,10 +3,10 @@ import DS from 'ember-data'; import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ - full_name: DS.attr('string'), - given_name: DS.attr('string'), - middle_names: DS.attr(), - family_name: DS.attr('string'), + fullName: DS.attr('string'), + givenName: DS.attr('string'), + middleNames: DS.attr(), + familyName: DS.attr('string'), nodes: DS.hasMany('nodes') }); From 09b19d61eac932c837e6b68dfc1fdcb488cd8667 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 12 May 2016 09:57:57 -0400 Subject: [PATCH 101/959] Move file tree component to a pod --- .../components/{file-tree.js => files-tree/component.js} | 2 +- tests/dummy/app/components/files-tree/style.scss | 7 +++++++ .../file-tree.hbs => components/files-tree/template.hbs} | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) rename tests/dummy/app/components/{file-tree.js => files-tree/component.js} (59%) create mode 100644 tests/dummy/app/components/files-tree/style.scss rename tests/dummy/app/{templates/components/file-tree.hbs => components/files-tree/template.hbs} (71%) diff --git a/tests/dummy/app/components/file-tree.js b/tests/dummy/app/components/files-tree/component.js similarity index 59% rename from tests/dummy/app/components/file-tree.js rename to tests/dummy/app/components/files-tree/component.js index 8311e31bc..8ef0d629f 100644 --- a/tests/dummy/app/components/file-tree.js +++ b/tests/dummy/app/components/files-tree/component.js @@ -1,5 +1,5 @@ import Ember from 'ember'; -import layout from '../templates/components/file-tree'; +import layout from './template'; export default Ember.Component.extend({ layout diff --git a/tests/dummy/app/components/files-tree/style.scss b/tests/dummy/app/components/files-tree/style.scss new file mode 100644 index 000000000..7ee6ca5c9 --- /dev/null +++ b/tests/dummy/app/components/files-tree/style.scss @@ -0,0 +1,7 @@ +.files-tree { + padding-left: 1em; +} + +.files-tree .folder-list { + border-left: 1px solid #ccc; +} diff --git a/tests/dummy/app/templates/components/file-tree.hbs b/tests/dummy/app/components/files-tree/template.hbs similarity index 71% rename from tests/dummy/app/templates/components/file-tree.hbs rename to tests/dummy/app/components/files-tree/template.hbs index bbeaba6d7..f0ce91326 100644 --- a/tests/dummy/app/templates/components/file-tree.hbs +++ b/tests/dummy/app/components/files-tree/template.hbs @@ -1,7 +1,7 @@ -
+
{{#if model.isFolder}} -
+
{{#each model.files as |file|}} {{file-tree model=file}} {{/each}} From 5b83bb9faab3153510494b3e35b0132a96316cc6 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 12 May 2016 10:02:25 -0400 Subject: [PATCH 102/959] File tree typo --- tests/dummy/app/components/files-tree/template.hbs | 2 +- tests/dummy/app/templates/nodes/detail/files.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/dummy/app/components/files-tree/template.hbs b/tests/dummy/app/components/files-tree/template.hbs index f0ce91326..3d4ef3651 100644 --- a/tests/dummy/app/components/files-tree/template.hbs +++ b/tests/dummy/app/components/files-tree/template.hbs @@ -3,7 +3,7 @@ {{#if model.isFolder}}
{{#each model.files as |file|}} - {{file-tree model=file}} + {{files-tree model=file}} {{/each}}
{{/if}} diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs index f0474048b..5b54e0bd6 100644 --- a/tests/dummy/app/templates/nodes/detail/files.hbs +++ b/tests/dummy/app/templates/nodes/detail/files.hbs @@ -1,5 +1,5 @@
{{#each model.files as |provider|}} - {{file-tree model=provider}} + {{files-tree model=provider}} {{/each}}
From 9ef4bd75a2e7e19d309e1d158f03ef4ff4be0565 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 12 May 2016 10:08:45 -0400 Subject: [PATCH 103/959] Fix user model and hbs templates --- addon/models/user.js | 2 ++ tests/dummy/app/templates/users/detail.hbs | 4 ++-- tests/dummy/app/templates/users/index.hbs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addon/models/user.js b/addon/models/user.js index 013227338..0506bde4c 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -8,6 +8,8 @@ export default OsfModel.extend({ middleNames: DS.attr(), familyName: DS.attr('string'), + dateRegistered: DS.attr('date'), + nodes: DS.hasMany('nodes'), registrations: DS.hasMany('registrations'), diff --git a/tests/dummy/app/templates/users/detail.hbs b/tests/dummy/app/templates/users/detail.hbs index 7ccb3d0d3..da6918a26 100644 --- a/tests/dummy/app/templates/users/detail.hbs +++ b/tests/dummy/app/templates/users/detail.hbs @@ -1,7 +1,7 @@ {{link-to 'Back to list' 'users' class="btn btn-default"}}
-

{{model.full_name}}

-

{{moment-format model.date_registered}}

+

{{model.fullName}}

+

{{moment-format model.dateRegistered}}

View on OSF diff --git a/tests/dummy/app/templates/users/index.hbs b/tests/dummy/app/templates/users/index.hbs index 4a38e7165..75ef77958 100644 --- a/tests/dummy/app/templates/users/index.hbs +++ b/tests/dummy/app/templates/users/index.hbs @@ -2,8 +2,8 @@


{{#each model as |user|}}
-

{{user.full_name}}

-

{{moment-format user.date_registered}}

+

{{user.fullName}}

+

{{moment-format user.dateRegistered}}

From 8ac9c777b570d71403e5b624134880e06ad8dff6 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 12 May 2016 10:27:02 -0400 Subject: [PATCH 104/959] List user's nodes, registrations and institutions In the user detail route, list the user's nodes, registrations and institutions. --- tests/dummy/app/templates/users/detail.hbs | 55 ++++++++++++++++++---- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/tests/dummy/app/templates/users/detail.hbs b/tests/dummy/app/templates/users/detail.hbs index da6918a26..23f7a3bff 100644 --- a/tests/dummy/app/templates/users/detail.hbs +++ b/tests/dummy/app/templates/users/detail.hbs @@ -1,11 +1,50 @@ {{link-to 'Back to list' 'users' class="btn btn-default"}}

-

{{model.fullName}}

-

{{moment-format model.dateRegistered}}

-

- - View on OSF - -

-
+

Data

+

{{model.fullName}}

+

{{moment-format model.dateRegistered}}

+

+ + View on OSF + +

+
+

Nodes

+ + + + + + {{#each model.nodes as |node|}} + + + + + {{/each}} +
IDTitle
{{node.id}}{{node.title}}
+
+

Registrations

+ + + + + + {{#each model.registrations as |registration|}} + + + + + {{/each}} +
IDTitle
{{registration.id}}{{registration.title}}
+
+

Affiliated Institutions

+

+ + {{#each model.affiliatedInstitutions as |inst|}} + + {{inst.name}} + + {{/each}} +
+

From 3297ee210c941da0256941b7a2cf67ada36747f3 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 12 May 2016 11:18:04 -0400 Subject: [PATCH 105/959] File detail with versions and comments --- addon/models/file-contents.js | 2 +- addon/models/file.js | 7 ++-- .../app/components/files-tree/template.hbs | 10 +++-- tests/dummy/app/router.js | 3 ++ tests/dummy/app/routes/file.js | 7 ++++ tests/dummy/app/templates/file.hbs | 42 +++++++++++++++++++ tests/dummy/app/templates/nodes/detail.hbs | 6 +-- 7 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 tests/dummy/app/routes/file.js create mode 100644 tests/dummy/app/templates/file.hbs diff --git a/addon/models/file-contents.js b/addon/models/file-contents.js index ec0a39394..d3d7a8056 100644 --- a/addon/models/file-contents.js +++ b/addon/models/file-contents.js @@ -3,5 +3,5 @@ import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ - // TODO waterbutler file + // TODO fetch file content from waterbutler }); diff --git a/addon/models/file.js b/addon/models/file.js index 4dfdf8364..c6b4a78d6 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -8,14 +8,14 @@ export default OsfModel.extend({ kind: DS.attr('string'), path: DS.attr('string'), size: DS.attr('number'), - provider: DS.belongsTo('string'), + provider: DS.attr('string'), materializedPath: DS.attr('string'), lastTouched: DS.attr('date'), dateModified: DS.attr('date'), dateCreated: DS.attr('date'), - parentFolder: DS.belongsTo('file'), + checkout: DS.attr(), extra: DS.attr(), // Folder attributes @@ -24,8 +24,9 @@ export default OsfModel.extend({ // File attributes versions: DS.hasMany('file-version'), comments: DS.hasMany('comment'), - contents: DS.belongsTo('file-contents'), + //contents: DS.belongsTo('file-contents'), + parentFolder: DS.belongsTo('file'), isFolder: Ember.computed.equal('kind', 'folder'), }); diff --git a/tests/dummy/app/components/files-tree/template.hbs b/tests/dummy/app/components/files-tree/template.hbs index 3d4ef3651..4589ecb3b 100644 --- a/tests/dummy/app/components/files-tree/template.hbs +++ b/tests/dummy/app/components/files-tree/template.hbs @@ -1,10 +1,12 @@ -
+

{{#if model.isFolder}} -

+

{{#each model.files as |file|}} {{files-tree model=file}} {{/each}} -

+

+ {{else}} + ({{link-to 'details' 'file' model}}) {{/if}} -
+

diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 61236c189..fe0e1d7f1 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -27,6 +27,9 @@ Router.map(function() { path: '/:registration_id' }); }); + this.route('file', { + path: '/file/:file_id' + }); }); export default Router; diff --git a/tests/dummy/app/routes/file.js b/tests/dummy/app/routes/file.js new file mode 100644 index 000000000..06fb0e691 --- /dev/null +++ b/tests/dummy/app/routes/file.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model(params) { + return this.store.findRecord('file', params.file_id); + } +}); diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs new file mode 100644 index 000000000..35c6a66a2 --- /dev/null +++ b/tests/dummy/app/templates/file.hbs @@ -0,0 +1,42 @@ +
+

File detail

+

{{model.name}}

+

{{model.kind}}

+

{{model.path}}

+

{{model.size}}

+

{{model.provider}}

+

{{model.materializedPath}}

+

{{model.lastTouched}}

+

{{model.dateModified}}

+

{{model.dateCreated}}

+

{{model.checkout}}

+ + View on OSF + + +
+

Versions

+
    + {{#each model.versions as |version|}} +
  • +
    {{version.id}}
    +
    {{version.size}}
    +
    {{version.contentType}}
    +
  • + {{else}} + (none) + {{/each}} +
+
+

Comments

+
    + {{#each model.comments as |comment|}} +
  • +
    {{comment.content}}
    +
  • + {{else}} + (none) + {{/each}} +
+ +
diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 5fce29271..0172728c6 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -44,7 +44,7 @@

Files

- {{link-to 'Show File Tree' 'nodes.detail.files' model.id}} - - {{outlet}} + {{#each model.files as |provider|}} + {{files-tree model=provider}} + {{/each}}
From 0a77b1349ad6ec6c80a43a736d29d68e4e9af34d Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 12 May 2016 11:24:44 -0400 Subject: [PATCH 106/959] Remove unnecessary route --- tests/dummy/app/router.js | 2 -- tests/dummy/app/routes/nodes/detail/files.js | 4 ---- tests/dummy/app/templates/file.hbs | 3 --- tests/dummy/app/templates/nodes/detail/files.hbs | 5 ----- 4 files changed, 14 deletions(-) delete mode 100644 tests/dummy/app/routes/nodes/detail/files.js delete mode 100644 tests/dummy/app/templates/nodes/detail/files.hbs diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index fe0e1d7f1..1d16140db 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -12,8 +12,6 @@ Router.map(function() { this.route('nodes', function() { this.route('detail', { path: '/:node_id' - }, function() { - this.route('files'); }); }); this.route('login'); diff --git a/tests/dummy/app/routes/nodes/detail/files.js b/tests/dummy/app/routes/nodes/detail/files.js deleted file mode 100644 index 26d9f3124..000000000 --- a/tests/dummy/app/routes/nodes/detail/files.js +++ /dev/null @@ -1,4 +0,0 @@ -import Ember from 'ember'; - -export default Ember.Route.extend({ -}); diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs index 35c6a66a2..b00d399d7 100644 --- a/tests/dummy/app/templates/file.hbs +++ b/tests/dummy/app/templates/file.hbs @@ -10,9 +10,6 @@

{{model.dateModified}}

{{model.dateCreated}}

{{model.checkout}}

- - View on OSF -

Versions

diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs deleted file mode 100644 index 5b54e0bd6..000000000 --- a/tests/dummy/app/templates/nodes/detail/files.hbs +++ /dev/null @@ -1,5 +0,0 @@ -
- {{#each model.files as |provider|}} - {{files-tree model=provider}} - {{/each}} -
From 5b49e4da40ae64f2e11c34b754ed792d09aa6173 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 11:44:28 -0400 Subject: [PATCH 107/959] Add first attempt at log model. --- addon/models/log.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 addon/models/log.js diff --git a/addon/models/log.js b/addon/models/log.js new file mode 100644 index 000000000..16fb62867 --- /dev/null +++ b/addon/models/log.js @@ -0,0 +1,18 @@ +import DS from 'ember-data'; +import OsfModel from 'ember-osf/models/base'; + +export default OsfModel.extend({ + date: DS.attr('date'), + action: DS.attr('string'), + params: DS.attr(), + + node: DS.belongsTo('node', { + inverse: null + }), + original_node: DS.belongsTo('node', {inverse: 'logs'}), + user: DS.belongsTo('user'), + linked_node: DS.belongsTo('node'), + template_node: DS.belongsTo('node', { + inverse: 'templateFrom' + }) +}); From 8cc662e3e629b06a085bdb274291e3802b2fc39b Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 11:44:44 -0400 Subject: [PATCH 108/959] Uncomment logs relationship in node model. --- addon/models/node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/models/node.js b/addon/models/node.js index 5985e35d4..b41007a71 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -35,6 +35,6 @@ export default OsfModel.extend({ //nodeLinks: DS.hasMany('node-pointers'), //registrations: DS.hasMany('registrations'), //primaryInistution: DS.belongsTo('institution'), - root: DS.belongsTo('node') - //logs: DS.hasMany('node-logs'), + root: DS.belongsTo('node'), + logs: DS.hasMany('logs') }); From ecb31a383e5031328c93679858d471ab582f2eb1 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 12 May 2016 11:44:58 -0400 Subject: [PATCH 109/959] Authenticate for file route --- addon/models/file-provider.js | 2 +- tests/dummy/app/routes/file.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index 8d926d9b7..a3b02e91d 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -7,9 +7,9 @@ export default OsfModel.extend({ kind: DS.attr('string'), name: DS.attr('string'), path: DS.attr('string'), - //node: DS.belongsTo('node'), provider: DS.attr('string'), files: DS.hasMany('file'), + node: DS.belongsTo('node'), isFolder: Ember.computed.equal('kind', 'folder'), }); diff --git a/tests/dummy/app/routes/file.js b/tests/dummy/app/routes/file.js index 06fb0e691..32b35b0e8 100644 --- a/tests/dummy/app/routes/file.js +++ b/tests/dummy/app/routes/file.js @@ -1,6 +1,7 @@ import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Ember.Route.extend({ +export default Ember.Route.extend(AuthenticatedRouteMixin, { model(params) { return this.store.findRecord('file', params.file_id); } From f7fea4785eca5aa0bab13c95085896633233f86c Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 11:45:56 -0400 Subject: [PATCH 110/959] Add first page of node log data to node detail template. --- app/models/log.js | 1 + tests/dummy/app/styles/app.css | 8 ++++++++ tests/dummy/app/templates/nodes/detail.hbs | 17 ++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/models/log.js diff --git a/app/models/log.js b/app/models/log.js new file mode 100644 index 000000000..c75349dd4 --- /dev/null +++ b/app/models/log.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/log'; diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.css index e69de29bb..0549d9fb2 100644 --- a/tests/dummy/app/styles/app.css +++ b/tests/dummy/app/styles/app.css @@ -0,0 +1,8 @@ +table { + border-collapse: separate; + border-spacing: 5px 0; +} + +td { + padding: 10px 0; +} diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 914145e0f..3f5e9eb66 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -4,6 +4,7 @@

{{model.category}}

{{moment-format model.dateCreated}}

{{moment-format model.dateModified}}

+

{{model.public}}

View on OSF @@ -22,5 +23,19 @@

-
+ + + {{#each model.logs as |node-log|}} + + + + + + + + + + {{/each}} +
{{node-log.action}} for {{node-log.original_node.id}} by {{node-log.user.given_name}} on {{moment-format node-log.date}}
+
From 95b382f2379f2597c65800aa2c4b3a3038bbcf6d Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 12 May 2016 11:53:06 -0400 Subject: [PATCH 111/959] Isolate apiv2-specific behavioes By not making the application adapter/serializer/ base model specific to one API, we have room to support othe rmicroservices such as WB. Uses mixins where we just add properties, and classes where we need a whole different parent (eg not JSONAPI-*) [#EOSF-33] --- addon/adapters/comment-report.js | 4 ++++ addon/adapters/comment.js | 4 ++++ addon/adapters/contributor.js | 4 ++++ addon/adapters/institution.js | 4 ++++ addon/adapters/node.js | 4 ++-- addon/adapters/{application.js => osf-adapter.js} | 7 ++++--- addon/adapters/registration.js | 4 ++++ addon/adapters/user.js | 4 ++++ addon/mixins/osf-model.js | 11 +++++++++++ addon/models/base.js | 6 ------ addon/models/comment-report.js | 4 +++- addon/models/comment.js | 4 ++-- addon/models/contributor.js | 4 ++-- addon/models/institution.js | 4 ++-- addon/models/node.js | 4 ++-- addon/models/registration.js | 2 +- addon/models/user.js | 4 ++-- addon/serializers/comment-report.js | 4 ++++ addon/serializers/comment.js | 4 ++++ addon/serializers/contributor.js | 4 ++++ addon/serializers/institution.js | 4 ++++ addon/serializers/node.js | 4 ++++ .../{application.js => osf-serializer.js} | 5 +++-- addon/serializers/registration.js | 4 ++++ addon/serializers/user.js | 4 ++++ app/adapters/application.js | 1 - app/adapters/comment-report.js | 1 + app/adapters/comment.js | 1 + app/adapters/contributor.js | 1 + app/adapters/institution.js | 1 + app/adapters/osf-adapter.js | 1 + app/adapters/registration.js | 1 + app/adapters/user.js | 1 + app/models/base.js | 1 - app/serializers/application.js | 1 - app/serializers/comment-report.js | 1 + app/serializers/comment.js | 1 + app/serializers/contributor.js | 1 + app/serializers/institution.js | 1 + app/serializers/node.js | 1 + app/serializers/osf-serializer.js | 1 + app/serializers/registration.js | 1 + app/serializers/user.js | 1 + tests/unit/adapters/comment-report-test.js | 12 ++++++++++++ tests/unit/adapters/comment-test.js | 12 ++++++++++++ .../{application-test.js => contributor-test.js} | 2 +- tests/unit/adapters/institution-test.js | 12 ++++++++++++ tests/unit/adapters/osf-adapter-test.js | 12 ++++++++++++ tests/unit/adapters/registration-test.js | 12 ++++++++++++ tests/unit/adapters/user-test.js | 12 ++++++++++++ tests/unit/mixins/osf-model-test.js | 12 ++++++++++++ tests/unit/models/base-test.js | 6 ------ tests/unit/serializers/application-test.js | 2 +- tests/unit/serializers/comment-report-test.js | 15 +++++++++++++++ tests/unit/serializers/comment-test.js | 15 +++++++++++++++ tests/unit/serializers/contributor-test.js | 15 +++++++++++++++ tests/unit/serializers/institution-test.js | 15 +++++++++++++++ tests/unit/serializers/node-test.js | 15 +++++++++++++++ tests/unit/serializers/osf-serializer-test.js | 15 +++++++++++++++ tests/unit/serializers/registration-test.js | 15 +++++++++++++++ tests/unit/serializers/user-test.js | 15 +++++++++++++++ 61 files changed, 307 insertions(+), 36 deletions(-) create mode 100644 addon/adapters/comment-report.js create mode 100644 addon/adapters/comment.js create mode 100644 addon/adapters/contributor.js create mode 100644 addon/adapters/institution.js rename addon/adapters/{application.js => osf-adapter.js} (91%) create mode 100644 addon/adapters/registration.js create mode 100644 addon/adapters/user.js create mode 100644 addon/mixins/osf-model.js delete mode 100644 addon/models/base.js create mode 100644 addon/serializers/comment-report.js create mode 100644 addon/serializers/comment.js create mode 100644 addon/serializers/contributor.js create mode 100644 addon/serializers/institution.js create mode 100644 addon/serializers/node.js rename addon/serializers/{application.js => osf-serializer.js} (92%) create mode 100644 addon/serializers/registration.js create mode 100644 addon/serializers/user.js delete mode 100644 app/adapters/application.js create mode 100644 app/adapters/comment-report.js create mode 100644 app/adapters/comment.js create mode 100644 app/adapters/contributor.js create mode 100644 app/adapters/institution.js create mode 100644 app/adapters/osf-adapter.js create mode 100644 app/adapters/registration.js create mode 100644 app/adapters/user.js delete mode 100644 app/models/base.js delete mode 100644 app/serializers/application.js create mode 100644 app/serializers/comment-report.js create mode 100644 app/serializers/comment.js create mode 100644 app/serializers/contributor.js create mode 100644 app/serializers/institution.js create mode 100644 app/serializers/node.js create mode 100644 app/serializers/osf-serializer.js create mode 100644 app/serializers/registration.js create mode 100644 app/serializers/user.js create mode 100644 tests/unit/adapters/comment-report-test.js create mode 100644 tests/unit/adapters/comment-test.js rename tests/unit/adapters/{application-test.js => contributor-test.js} (81%) create mode 100644 tests/unit/adapters/institution-test.js create mode 100644 tests/unit/adapters/osf-adapter-test.js create mode 100644 tests/unit/adapters/registration-test.js create mode 100644 tests/unit/adapters/user-test.js create mode 100644 tests/unit/mixins/osf-model-test.js delete mode 100644 tests/unit/models/base-test.js create mode 100644 tests/unit/serializers/comment-report-test.js create mode 100644 tests/unit/serializers/comment-test.js create mode 100644 tests/unit/serializers/contributor-test.js create mode 100644 tests/unit/serializers/institution-test.js create mode 100644 tests/unit/serializers/node-test.js create mode 100644 tests/unit/serializers/osf-serializer-test.js create mode 100644 tests/unit/serializers/registration-test.js create mode 100644 tests/unit/serializers/user-test.js diff --git a/addon/adapters/comment-report.js b/addon/adapters/comment-report.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/comment-report.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/adapters/comment.js b/addon/adapters/comment.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/comment.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/adapters/contributor.js b/addon/adapters/contributor.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/contributor.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/adapters/institution.js b/addon/adapters/institution.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/institution.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 3185c8376..1dc9ec289 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -1,6 +1,6 @@ -import ApplicationAdapter from './application'; +import OsfAdapter from './osf-adapter'; -export default ApplicationAdapter.extend({ +export default OsfAdapter.extend({ buildURL(_, __, ___, requestType) { // Embed contributors var base = this._super(...arguments); diff --git a/addon/adapters/application.js b/addon/adapters/osf-adapter.js similarity index 91% rename from addon/adapters/application.js rename to addon/adapters/osf-adapter.js index cff7dd94b..5328213b1 100644 --- a/addon/adapters/application.js +++ b/addon/adapters/osf-adapter.js @@ -1,14 +1,15 @@ -import Ember from 'ember'; +/* + Base adapter class for all OSF APIv2 endpoints + */ import DS from 'ember-data'; -import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; import config from 'ember-get-config'; +import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { authorizer: 'authorizer:osf-token', host: config.OSF.apiUrl, namespace: config.OSF.apiNamespace, - pathForType: Ember.String.pluralize, buildURL(modelName, id, snapshot, requestType, query) { // jshint ignore:line var url = this._super(...arguments); diff --git a/addon/adapters/registration.js b/addon/adapters/registration.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/registration.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/adapters/user.js b/addon/adapters/user.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/user.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/mixins/osf-model.js b/addon/mixins/osf-model.js new file mode 100644 index 000000000..a2b7fbd2f --- /dev/null +++ b/addon/mixins/osf-model.js @@ -0,0 +1,11 @@ +/* + Common properties and behaviors shared by all OSF APIv2 models + */ + +import Ember from 'ember'; +import DS from 'ember-data'; + +export default Ember.Mixin.create({ + links: DS.attr('links'), + embeds: DS.attr('embed') +}); diff --git a/addon/models/base.js b/addon/models/base.js deleted file mode 100644 index 67a215787..000000000 --- a/addon/models/base.js +++ /dev/null @@ -1,6 +0,0 @@ -import DS from 'ember-data'; - -export default DS.Model.extend({ - links: DS.attr('links'), - embeds: DS.attr('embed') -}); diff --git a/addon/models/comment-report.js b/addon/models/comment-report.js index c3e00c482..eea65b0f0 100644 --- a/addon/models/comment-report.js +++ b/addon/models/comment-report.js @@ -1,6 +1,8 @@ import DS from 'ember-data'; -export default DS.Model.extend({ +import OsfModel from '../mixins/osf-model'; + +export default DS.Model.extend(OsfModel, { category: DS.attr('string'), text: DS.belongsTo('comment') }); diff --git a/addon/models/comment.js b/addon/models/comment.js index b1d5e4850..b31849f43 100644 --- a/addon/models/comment.js +++ b/addon/models/comment.js @@ -1,8 +1,8 @@ import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from '../mixins/osf-model'; -export default OsfModel.extend({ +export default DS.Model.extend(OsfModel, { type: DS.attr('string'), // TODO validation: maxLength content: DS.attr('string'), diff --git a/addon/models/contributor.js b/addon/models/contributor.js index b452976e5..8d469b953 100644 --- a/addon/models/contributor.js +++ b/addon/models/contributor.js @@ -1,8 +1,8 @@ import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from '../mixins/osf-model'; -export default OsfModel.extend({ +export default DS.Model.extend(OsfModel, { bibliographic: DS.attr('boolean'), permission: DS.attr('string'), users: DS.hasMany('user') diff --git a/addon/models/institution.js b/addon/models/institution.js index daa14ddf0..c5ccd1614 100644 --- a/addon/models/institution.js +++ b/addon/models/institution.js @@ -1,8 +1,8 @@ import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from '../mixins/osf-model'; -export default OsfModel.extend({ +export default DS.Model.extend(OsfModel, { name: DS.attr('string'), description: DS.attr('string'), logoPath: DS.attr('string'), diff --git a/addon/models/node.js b/addon/models/node.js index f467c6013..d0cfd10bf 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -1,8 +1,8 @@ import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from '../mixins/osf-model'; -export default OsfModel.extend({ +export default DS.Model.extend(OsfModel, { title: DS.attr('string'), description: DS.attr('string'), category: DS.attr('string'), diff --git a/addon/models/registration.js b/addon/models/registration.js index 28ad9142a..82cd5fb9e 100644 --- a/addon/models/registration.js +++ b/addon/models/registration.js @@ -1,6 +1,6 @@ import DS from 'ember-data'; -import Node from 'ember-osf/models/node'; +import Node from '../models/node'; export default Node.extend({ dateRegistered: DS.attr('date'), diff --git a/addon/models/user.js b/addon/models/user.js index 33a8ed418..c3e7e8974 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -1,8 +1,8 @@ import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from 'ember-osf/mixins/osf-model'; -export default OsfModel.extend({ +export default DS.Model.extend(OsfModel, { given_name: DS.attr('string'), middle_names: DS.attr(), family_name: DS.attr('string'), diff --git a/addon/serializers/comment-report.js b/addon/serializers/comment-report.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/comment-report.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/addon/serializers/comment.js b/addon/serializers/comment.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/comment.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/addon/serializers/contributor.js b/addon/serializers/contributor.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/contributor.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/addon/serializers/institution.js b/addon/serializers/institution.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/institution.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/addon/serializers/node.js b/addon/serializers/node.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/node.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/addon/serializers/application.js b/addon/serializers/osf-serializer.js similarity index 92% rename from addon/serializers/application.js rename to addon/serializers/osf-serializer.js index 7ba903175..6d5eba9a2 100644 --- a/addon/serializers/application.js +++ b/addon/serializers/osf-serializer.js @@ -1,9 +1,10 @@ +/* + Base serializer class for all OSF APIv2 endpoints + */ import Ember from 'ember'; import DS from 'ember-data'; export default DS.JSONAPISerializer.extend({ - - // TODO: Pre-1.0, refactor this into a separate OSF serializer, so we can support other microservices such as WB attrs: { links: { serialize: false diff --git a/addon/serializers/registration.js b/addon/serializers/registration.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/registration.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/addon/serializers/user.js b/addon/serializers/user.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/user.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/app/adapters/application.js b/app/adapters/application.js deleted file mode 100644 index 394d6c1c5..000000000 --- a/app/adapters/application.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/adapters/application'; diff --git a/app/adapters/comment-report.js b/app/adapters/comment-report.js new file mode 100644 index 000000000..1848d5bd9 --- /dev/null +++ b/app/adapters/comment-report.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/comment-report'; diff --git a/app/adapters/comment.js b/app/adapters/comment.js new file mode 100644 index 000000000..351739f9d --- /dev/null +++ b/app/adapters/comment.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/comment'; diff --git a/app/adapters/contributor.js b/app/adapters/contributor.js new file mode 100644 index 000000000..9103af15a --- /dev/null +++ b/app/adapters/contributor.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/contributor'; diff --git a/app/adapters/institution.js b/app/adapters/institution.js new file mode 100644 index 000000000..d8c2c4697 --- /dev/null +++ b/app/adapters/institution.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/institution'; diff --git a/app/adapters/osf-adapter.js b/app/adapters/osf-adapter.js new file mode 100644 index 000000000..905c9a673 --- /dev/null +++ b/app/adapters/osf-adapter.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/osf-adapter'; diff --git a/app/adapters/registration.js b/app/adapters/registration.js new file mode 100644 index 000000000..827a99222 --- /dev/null +++ b/app/adapters/registration.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/registration'; diff --git a/app/adapters/user.js b/app/adapters/user.js new file mode 100644 index 000000000..bdea9ac19 --- /dev/null +++ b/app/adapters/user.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/user'; diff --git a/app/models/base.js b/app/models/base.js deleted file mode 100644 index 0a6182209..000000000 --- a/app/models/base.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/models/base'; diff --git a/app/serializers/application.js b/app/serializers/application.js deleted file mode 100644 index 4c9ed2b4e..000000000 --- a/app/serializers/application.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/serializers/application'; diff --git a/app/serializers/comment-report.js b/app/serializers/comment-report.js new file mode 100644 index 000000000..5d46e1e0e --- /dev/null +++ b/app/serializers/comment-report.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/comment-report'; diff --git a/app/serializers/comment.js b/app/serializers/comment.js new file mode 100644 index 000000000..9d578cb23 --- /dev/null +++ b/app/serializers/comment.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/comment'; diff --git a/app/serializers/contributor.js b/app/serializers/contributor.js new file mode 100644 index 000000000..fa26840ec --- /dev/null +++ b/app/serializers/contributor.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/contributor'; diff --git a/app/serializers/institution.js b/app/serializers/institution.js new file mode 100644 index 000000000..cd2069a0a --- /dev/null +++ b/app/serializers/institution.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/institution'; diff --git a/app/serializers/node.js b/app/serializers/node.js new file mode 100644 index 000000000..fa842fca6 --- /dev/null +++ b/app/serializers/node.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/node'; diff --git a/app/serializers/osf-serializer.js b/app/serializers/osf-serializer.js new file mode 100644 index 000000000..eec142038 --- /dev/null +++ b/app/serializers/osf-serializer.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/osf-serializer'; diff --git a/app/serializers/registration.js b/app/serializers/registration.js new file mode 100644 index 000000000..cb9033d51 --- /dev/null +++ b/app/serializers/registration.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/registration'; diff --git a/app/serializers/user.js b/app/serializers/user.js new file mode 100644 index 000000000..fcebd5ec2 --- /dev/null +++ b/app/serializers/user.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/user'; diff --git a/tests/unit/adapters/comment-report-test.js b/tests/unit/adapters/comment-report-test.js new file mode 100644 index 000000000..db86a5d41 --- /dev/null +++ b/tests/unit/adapters/comment-report-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:comment-report', 'Unit | Adapter | comment report', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/adapters/comment-test.js b/tests/unit/adapters/comment-test.js new file mode 100644 index 000000000..0f9aed191 --- /dev/null +++ b/tests/unit/adapters/comment-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:comment', 'Unit | Adapter | comment', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/adapters/application-test.js b/tests/unit/adapters/contributor-test.js similarity index 81% rename from tests/unit/adapters/application-test.js rename to tests/unit/adapters/contributor-test.js index f0a2101e7..eed33c511 100644 --- a/tests/unit/adapters/application-test.js +++ b/tests/unit/adapters/contributor-test.js @@ -1,6 +1,6 @@ import { moduleFor, test } from 'ember-qunit'; -moduleFor('adapter:application', 'Unit | Adapter | application', { +moduleFor('adapter:contributor', 'Unit | Adapter | contributor', { // Specify the other units that are required for this test. // needs: ['serializer:foo'] }); diff --git a/tests/unit/adapters/institution-test.js b/tests/unit/adapters/institution-test.js new file mode 100644 index 000000000..c19c9cbf6 --- /dev/null +++ b/tests/unit/adapters/institution-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:institution', 'Unit | Adapter | institution', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/adapters/osf-adapter-test.js b/tests/unit/adapters/osf-adapter-test.js new file mode 100644 index 000000000..f07f2e6be --- /dev/null +++ b/tests/unit/adapters/osf-adapter-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:osf-adapter', 'Unit | Adapter | osf adapter', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/adapters/registration-test.js b/tests/unit/adapters/registration-test.js new file mode 100644 index 000000000..d65d14274 --- /dev/null +++ b/tests/unit/adapters/registration-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:registration', 'Unit | Adapter | registration', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/adapters/user-test.js b/tests/unit/adapters/user-test.js new file mode 100644 index 000000000..39da04368 --- /dev/null +++ b/tests/unit/adapters/user-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:user', 'Unit | Adapter | user', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/mixins/osf-model-test.js b/tests/unit/mixins/osf-model-test.js new file mode 100644 index 000000000..286ac38b7 --- /dev/null +++ b/tests/unit/mixins/osf-model-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import OsfModelMixin from 'ember-osf/mixins/osf-model'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | osf model'); + +// Replace this with your real tests. +test('it works', function(assert) { + let OsfModelObject = Ember.Object.extend(OsfModelMixin); + let subject = OsfModelObject.create(); + assert.ok(subject); +}); diff --git a/tests/unit/models/base-test.js b/tests/unit/models/base-test.js deleted file mode 100644 index c40c5114b..000000000 --- a/tests/unit/models/base-test.js +++ /dev/null @@ -1,6 +0,0 @@ -import { moduleForModel /*, test*/ } from 'ember-qunit'; - -moduleForModel('base', 'Unit | Model | base', { - // Specify the other units that are required for this test. - needs: [] -}); diff --git a/tests/unit/serializers/application-test.js b/tests/unit/serializers/application-test.js index 77ab6a77c..68df6a98a 100644 --- a/tests/unit/serializers/application-test.js +++ b/tests/unit/serializers/application-test.js @@ -1,6 +1,6 @@ import { moduleForModel, test } from 'ember-qunit'; import { faker } from 'ember-cli-mirage'; - +// TODO: Move this to the osf-serializer tests file moduleForModel('base', 'Unit | Serializer | application', { needs: ['serializer:application'] }); diff --git a/tests/unit/serializers/comment-report-test.js b/tests/unit/serializers/comment-report-test.js new file mode 100644 index 000000000..d2facae37 --- /dev/null +++ b/tests/unit/serializers/comment-report-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('comment-report', 'Unit | Serializer | comment report', { + // Specify the other units that are required for this test. + needs: ['serializer:comment-report'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); diff --git a/tests/unit/serializers/comment-test.js b/tests/unit/serializers/comment-test.js new file mode 100644 index 000000000..d254b0643 --- /dev/null +++ b/tests/unit/serializers/comment-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('comment', 'Unit | Serializer | comment', { + // Specify the other units that are required for this test. + needs: ['serializer:comment'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); diff --git a/tests/unit/serializers/contributor-test.js b/tests/unit/serializers/contributor-test.js new file mode 100644 index 000000000..65ea5b2dc --- /dev/null +++ b/tests/unit/serializers/contributor-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('contributor', 'Unit | Serializer | contributor', { + // Specify the other units that are required for this test. + needs: ['serializer:contributor'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); diff --git a/tests/unit/serializers/institution-test.js b/tests/unit/serializers/institution-test.js new file mode 100644 index 000000000..538233783 --- /dev/null +++ b/tests/unit/serializers/institution-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('institution', 'Unit | Serializer | institution', { + // Specify the other units that are required for this test. + needs: ['serializer:institution'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); diff --git a/tests/unit/serializers/node-test.js b/tests/unit/serializers/node-test.js new file mode 100644 index 000000000..b79ba7400 --- /dev/null +++ b/tests/unit/serializers/node-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('node', 'Unit | Serializer | node', { + // Specify the other units that are required for this test. + needs: ['serializer:node'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); diff --git a/tests/unit/serializers/osf-serializer-test.js b/tests/unit/serializers/osf-serializer-test.js new file mode 100644 index 000000000..7f17ed15d --- /dev/null +++ b/tests/unit/serializers/osf-serializer-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('osf-serializer', 'Unit | Serializer | osf serializer', { + // Specify the other units that are required for this test. + needs: ['serializer:osf-serializer'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); diff --git a/tests/unit/serializers/registration-test.js b/tests/unit/serializers/registration-test.js new file mode 100644 index 000000000..5df643972 --- /dev/null +++ b/tests/unit/serializers/registration-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('registration', 'Unit | Serializer | registration', { + // Specify the other units that are required for this test. + needs: ['serializer:registration'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); diff --git a/tests/unit/serializers/user-test.js b/tests/unit/serializers/user-test.js new file mode 100644 index 000000000..19e4a38d0 --- /dev/null +++ b/tests/unit/serializers/user-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('user', 'Unit | Serializer | user', { + // Specify the other units that are required for this test. + needs: ['serializer:user'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); From 10ab69a0a44fa7491454f61306abc39b140c07f0 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 12 May 2016 11:57:12 -0400 Subject: [PATCH 112/959] Fix style errors, sorry --- addon/models/file-provider.js | 2 +- addon/models/file.js | 4 +--- addon/serializers/file-provider.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index a3b02e91d..ac66b3e9c 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -8,7 +8,7 @@ export default OsfModel.extend({ name: DS.attr('string'), path: DS.attr('string'), provider: DS.attr('string'), - files: DS.hasMany('file'), + files: DS.hasMany('file'), node: DS.belongsTo('node'), isFolder: Ember.computed.equal('kind', 'folder'), diff --git a/addon/models/file.js b/addon/models/file.js index c6b4a78d6..625d07f13 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -1,6 +1,5 @@ import Ember from 'ember'; import DS from 'ember-data'; - import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ @@ -19,14 +18,13 @@ export default OsfModel.extend({ extra: DS.attr(), // Folder attributes - files: DS.hasMany('file', {inverse: 'parentFolder'}), + files: DS.hasMany('file', { inverse: 'parentFolder' }), // File attributes versions: DS.hasMany('file-version'), comments: DS.hasMany('comment'), //contents: DS.belongsTo('file-contents'), - parentFolder: DS.belongsTo('file'), isFolder: Ember.computed.equal('kind', 'folder'), }); diff --git a/addon/serializers/file-provider.js b/addon/serializers/file-provider.js index 74c6b1e30..11d1cfeed 100644 --- a/addon/serializers/file-provider.js +++ b/addon/serializers/file-provider.js @@ -2,6 +2,6 @@ import JSONAPISerializer from 'ember-data/serializers/json-api'; export default JSONAPISerializer.extend({ modelNameFromPayloadKey() { - return "file-provider"; + return 'file-provider'; } }); From 292933dc9f07a91d5e8c3fd6c2a3a05cd77ea1dc Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 12 May 2016 11:58:55 -0400 Subject: [PATCH 113/959] Run style checks on dummy app - and fix the styling --- package.json | 2 +- tests/dummy/app/routes/application.js | 2 +- tests/dummy/app/routes/institutions.js | 6 +++--- tests/dummy/app/routes/nodes.js | 5 ++--- tests/dummy/app/routes/nodes/detail.js | 2 +- tests/dummy/app/routes/registrations.js | 9 ++++----- tests/dummy/app/routes/registrations/detail.js | 6 +++--- tests/dummy/app/routes/users/detail.js | 2 +- tests/helpers/start-app.js | 18 +++++++++--------- 9 files changed, 25 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 4f7fbfd8d..8ee38ab2f 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ }, "jscsConfig": { "preset": "airbnb", - "excludeFiles": ["bower_components", "dist", "tmp", "vendor", "app/locales", "tests"], + "excludeFiles": ["bower_components", "dist", "tmp", "vendor", "app/locales", "tests/unit", "tests/integration", "tests/helpers", "tests/dummy/app/mirage"], "requireSpacesInAnonymousFunctionExpression": false, "requireTrailingComma": false, "disallowTrailingComma": false, diff --git a/tests/dummy/app/routes/application.js b/tests/dummy/app/routes/application.js index 1eefa67c8..096270608 100644 --- a/tests/dummy/app/routes/application.js +++ b/tests/dummy/app/routes/application.js @@ -4,7 +4,7 @@ export default Ember.Route.extend({ store: Ember.inject.service(), session: Ember.inject.service(), model() { - if(this.get('session.isAuthenticated')) { + if (this.get('session.isAuthenticated')) { return this.get('store').findRecord('user', 'me'); } return null; diff --git a/tests/dummy/app/routes/institutions.js b/tests/dummy/app/routes/institutions.js index 52436fea8..5e022908a 100644 --- a/tests/dummy/app/routes/institutions.js +++ b/tests/dummy/app/routes/institutions.js @@ -1,7 +1,7 @@ import Ember from 'ember'; export default Ember.Route.extend({ - model() { - return this.store.findAll('institution'); - } + model() { + return this.store.findAll('institution'); + } }); diff --git a/tests/dummy/app/routes/nodes.js b/tests/dummy/app/routes/nodes.js index 0a3f1c5ef..aed5474f6 100644 --- a/tests/dummy/app/routes/nodes.js +++ b/tests/dummy/app/routes/nodes.js @@ -7,9 +7,8 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { model() { let user = this.modelFor('application'); if (user) { - return user.get('nodes'); // Fetch from `/users/me/nodes/` - } - else { + return user.get('nodes'); // Fetch from `/users/me/nodes/` + } else { return this.get('store').findRecord('user', 'me').then(user => user.get('nodes')); } }, diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index a90314bff..e1ea35f24 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -2,7 +2,7 @@ import Ember from 'ember'; export default Ember.Route.extend({ model(params) { - return this.store.findRecord('node', params.node_id); + return this.store.findRecord('node', params.node_id); }, setupController(controller, model) { diff --git a/tests/dummy/app/routes/registrations.js b/tests/dummy/app/routes/registrations.js index ed07c46c2..631a8e42f 100644 --- a/tests/dummy/app/routes/registrations.js +++ b/tests/dummy/app/routes/registrations.js @@ -6,11 +6,10 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { session: Ember.inject.service(), model() { let user = this.modelFor('application'); - if(user) { + if (user) { return user.get('registrations'); - } - else { - return this.get('store').findRecord('user', 'me').then(user => user.get('registrations')); - } + } else { + return this.get('store').findRecord('user', 'me').then(user => user.get('registrations')); + } } }); diff --git a/tests/dummy/app/routes/registrations/detail.js b/tests/dummy/app/routes/registrations/detail.js index 6f1415a30..52ef2e0a8 100644 --- a/tests/dummy/app/routes/registrations/detail.js +++ b/tests/dummy/app/routes/registrations/detail.js @@ -1,7 +1,7 @@ import Ember from 'ember'; export default Ember.Route.extend({ - model(params) { - return this.store.findRecord('registration', params.registration_id); - } + model(params) { + return this.store.findRecord('registration', params.registration_id); + } }); diff --git a/tests/dummy/app/routes/users/detail.js b/tests/dummy/app/routes/users/detail.js index 762ec37af..96987f038 100644 --- a/tests/dummy/app/routes/users/detail.js +++ b/tests/dummy/app/routes/users/detail.js @@ -2,6 +2,6 @@ import Ember from 'ember'; export default Ember.Route.extend({ model(params) { - return this.store.findRecord('user', params.user_id); + return this.store.findRecord('user', params.user_id); } }); diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js index e098f1d5b..ef1b6b55e 100644 --- a/tests/helpers/start-app.js +++ b/tests/helpers/start-app.js @@ -3,16 +3,16 @@ import Application from '../../app'; import config from '../../config/environment'; export default function startApp(attrs) { - let application; + let application; - let attributes = Ember.merge({}, config.APP); - attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; + let attributes = Ember.merge({}, config.APP); + attributes = Ember.merge(attributes, attrs); // use defaults, but you can override; - Ember.run(() => { - application = Application.create(attributes); - application.setupForTesting(); - application.injectTestHelpers(); - }); + Ember.run(() => { + application = Application.create(attributes); + application.setupForTesting(); + application.injectTestHelpers(); + }); - return application; + return application; } From 6dca6fa1885d10057a108c63d7b18e6a5cce0b56 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 12 May 2016 12:00:43 -0400 Subject: [PATCH 114/959] Use AuthenticatedRouteMixin in user detail route --- tests/dummy/app/routes/users/detail.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/dummy/app/routes/users/detail.js b/tests/dummy/app/routes/users/detail.js index 96987f038..3de7beedf 100644 --- a/tests/dummy/app/routes/users/detail.js +++ b/tests/dummy/app/routes/users/detail.js @@ -1,6 +1,7 @@ import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Ember.Route.extend({ +export default Ember.Route.extend(AuthenticatedRouteMixin, { model(params) { return this.store.findRecord('user', params.user_id); } From 5251afb6d53b3f53f65eef1e1dddfefe75b0cbd0 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 12:16:06 -0400 Subject: [PATCH 115/959] Move css to app.scss. --- tests/dummy/app/styles/app.scss | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/dummy/app/styles/app.scss b/tests/dummy/app/styles/app.scss index e69de29bb..0549d9fb2 100644 --- a/tests/dummy/app/styles/app.scss +++ b/tests/dummy/app/styles/app.scss @@ -0,0 +1,8 @@ +table { + border-collapse: separate; + border-spacing: 5px 0; +} + +td { + padding: 10px 0; +} From 6a235226d29b0568e13432624a34155286b81e56 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 12 May 2016 12:22:50 -0400 Subject: [PATCH 116/959] Fix failing unit tests... sorry again --- tests/unit/models/file-provider-test.js | 4 ++-- tests/unit/models/file-test.js | 4 ++-- tests/unit/models/node-test.js | 2 +- tests/unit/models/registration-test.js | 2 +- tests/unit/serializers/file-provider-test.js | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/unit/models/file-provider-test.js b/tests/unit/models/file-provider-test.js index 292afd2c3..60db71746 100644 --- a/tests/unit/models/file-provider-test.js +++ b/tests/unit/models/file-provider-test.js @@ -1,8 +1,8 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('file-provider', 'Unit | Model | file provider', { - // Specify the other units that are required for this test. - needs: [] + // Specify the other units that are required for this test. + needs: ['model:file', 'model:node'] }); test('it exists', function(assert) { diff --git a/tests/unit/models/file-test.js b/tests/unit/models/file-test.js index 225d0728a..5186dee1c 100644 --- a/tests/unit/models/file-test.js +++ b/tests/unit/models/file-test.js @@ -1,8 +1,8 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('file', 'Unit | Model | file', { - // Specify the other units that are required for this test. - needs: [] + // Specify the other units that are required for this test. + needs: ['model:file-version', 'model:comment'] }); test('it exists', function(assert) { diff --git a/tests/unit/models/node-test.js b/tests/unit/models/node-test.js index 95aac5c75..1b1a5a13f 100644 --- a/tests/unit/models/node-test.js +++ b/tests/unit/models/node-test.js @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('node', 'Unit | Model | node', { // Specify the other units that are required for this test. - needs: ['model:user', 'model:contributor', 'model:comment', 'model:institution', 'model:registration'] + needs: ['model:user', 'model:contributor', 'model:comment', 'model:institution', 'model:registration', 'model:file-provider'] }); test('it exists', function(assert) { diff --git a/tests/unit/models/registration-test.js b/tests/unit/models/registration-test.js index 10567c730..a1230f67b 100644 --- a/tests/unit/models/registration-test.js +++ b/tests/unit/models/registration-test.js @@ -5,7 +5,7 @@ import { moduleForModel('registration', 'Unit | Model | registration', { // Specify the other units that are required for this test. - needs: ['model:institution', 'model:node', 'model:user', 'model:contributor', 'model:comment'] + needs: ['model:institution', 'model:node', 'model:user', 'model:contributor', 'model:comment', 'model:file-provider'] }); test('it exists', function(assert) { diff --git a/tests/unit/serializers/file-provider-test.js b/tests/unit/serializers/file-provider-test.js index 8843093de..8ef4b4b6d 100644 --- a/tests/unit/serializers/file-provider-test.js +++ b/tests/unit/serializers/file-provider-test.js @@ -2,7 +2,8 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('file-provider', 'Unit | Serializer | file provider', { // Specify the other units that are required for this test. - needs: ['serializer:file-provider'] + needs: ['serializer:file-provider', 'model:file', 'model:node', + 'transform:links', 'transform:embed'] }); // Replace this with your real tests. From 88906dd769c55cfe7baee85f179bd6206e8a7ddc Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 12:23:36 -0400 Subject: [PATCH 117/959] Styling. --- addon/models/log.js | 11 ++++++----- tests/dummy/app/templates/nodes/detail.hbs | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/addon/models/log.js b/addon/models/log.js index 16fb62867..78290e66c 100644 --- a/addon/models/log.js +++ b/addon/models/log.js @@ -5,14 +5,15 @@ export default OsfModel.extend({ date: DS.attr('date'), action: DS.attr('string'), params: DS.attr(), - node: DS.belongsTo('node', { - inverse: null + inverse: null + }), + originalNode: DS.belongsTo('node', { + inverse: 'logs' }), - original_node: DS.belongsTo('node', {inverse: 'logs'}), user: DS.belongsTo('user'), linked_node: DS.belongsTo('node'), - template_node: DS.belongsTo('node', { - inverse: 'templateFrom' + templateNode: DS.belongsTo('node', { + inverse: 'templateFrom' }) }); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index dd3a35454..d196e8202 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -49,7 +49,7 @@ {{node-log.action}} for - {{node-log.original_node.id}} + {{node-log.originalNode.id}} by {{node-log.user.givenName}} on From 4d91532015a21bcd54bc952770677e2d6ca95150 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 12:24:39 -0400 Subject: [PATCH 118/959] Remove old line. --- addon/models/node.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addon/models/node.js b/addon/models/node.js index b5486554c..8e4a6000d 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -43,7 +43,6 @@ export default OsfModel.extend({ root: DS.belongsTo('node', { inverse: null }), - //logs: DS.hasMany('node-logs'), //primaryInstitution: DS.belongsTo('institution'), logs: DS.hasMany('logs') }); From fb57cf22a0a9e6d1690748f75e57fd0adb56cffc Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 13:07:00 -0400 Subject: [PATCH 119/959] Remove styling from app.css. --- tests/dummy/app/styles/app.css | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.css index 0549d9fb2..e69de29bb 100644 --- a/tests/dummy/app/styles/app.css +++ b/tests/dummy/app/styles/app.css @@ -1,8 +0,0 @@ -table { - border-collapse: separate; - border-spacing: 5px 0; -} - -td { - padding: 10px 0; -} From 1d84aeb6c52b69999d7009f5016204f41dc918be Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 12 May 2016 13:07:48 -0400 Subject: [PATCH 120/959] Fix one last style error --- tests/dummy/app/components/files-tree/component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dummy/app/components/files-tree/component.js b/tests/dummy/app/components/files-tree/component.js index 8ef0d629f..44bf16cc0 100644 --- a/tests/dummy/app/components/files-tree/component.js +++ b/tests/dummy/app/components/files-tree/component.js @@ -2,5 +2,5 @@ import Ember from 'ember'; import layout from './template'; export default Ember.Component.extend({ - layout + layout }); From 79c834d7e22eecedcfeb37675cfe648958f772d1 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 13:17:52 -0400 Subject: [PATCH 121/959] Add log information to registation template. --- tests/dummy/app/templates/nodes/detail.hbs | 2 +- .../app/templates/registrations/detail.hbs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index d196e8202..45690328d 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -43,7 +43,7 @@

- +

Recent Activity

{{#each model.logs as |node-log|}} diff --git a/tests/dummy/app/templates/registrations/detail.hbs b/tests/dummy/app/templates/registrations/detail.hbs index 263ab9fc9..0465e1b08 100644 --- a/tests/dummy/app/templates/registrations/detail.hbs +++ b/tests/dummy/app/templates/registrations/detail.hbs @@ -8,8 +8,23 @@ View on OSF

- +

{{link-to 'Node Registered' 'nodes.detail' model.registeredFrom.id class="btn btn-warning"}}

+

Recent Activity

+
+ {{#each model.logs as |node-log|}} + + + + + + + + + + {{/each}} +
{{node-log.action}} for {{node-log.originalNode.id}} by {{node-log.user.givenName}} on {{moment-format node-log.date}}
+
From 8c5fbb107b45da385e2bb523723d1bae2e09c08f Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 12 May 2016 13:38:32 -0400 Subject: [PATCH 122/959] Remove unused tests and move application serializer tests to osf-serializer file [ci skip] --- tests/unit/adapters/comment-report-test.js | 12 ------ tests/unit/adapters/comment-test.js | 12 ------ tests/unit/adapters/contributor-test.js | 12 ------ tests/unit/adapters/institution-test.js | 12 ------ tests/unit/adapters/registration-test.js | 12 ------ tests/unit/adapters/user-test.js | 12 ------ tests/unit/serializers/application-test.js | 39 ------------------- tests/unit/serializers/comment-report-test.js | 15 ------- tests/unit/serializers/comment-test.js | 15 ------- tests/unit/serializers/contributor-test.js | 15 ------- tests/unit/serializers/institution-test.js | 15 ------- tests/unit/serializers/node-test.js | 15 ------- tests/unit/serializers/osf-serializer-test.js | 39 +++++++++++++++---- tests/unit/serializers/registration-test.js | 15 ------- tests/unit/serializers/user-test.js | 15 ------- 15 files changed, 31 insertions(+), 224 deletions(-) delete mode 100644 tests/unit/adapters/comment-report-test.js delete mode 100644 tests/unit/adapters/comment-test.js delete mode 100644 tests/unit/adapters/contributor-test.js delete mode 100644 tests/unit/adapters/institution-test.js delete mode 100644 tests/unit/adapters/registration-test.js delete mode 100644 tests/unit/adapters/user-test.js delete mode 100644 tests/unit/serializers/application-test.js delete mode 100644 tests/unit/serializers/comment-report-test.js delete mode 100644 tests/unit/serializers/comment-test.js delete mode 100644 tests/unit/serializers/contributor-test.js delete mode 100644 tests/unit/serializers/institution-test.js delete mode 100644 tests/unit/serializers/node-test.js delete mode 100644 tests/unit/serializers/registration-test.js delete mode 100644 tests/unit/serializers/user-test.js diff --git a/tests/unit/adapters/comment-report-test.js b/tests/unit/adapters/comment-report-test.js deleted file mode 100644 index db86a5d41..000000000 --- a/tests/unit/adapters/comment-report-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('adapter:comment-report', 'Unit | Adapter | comment report', { - // Specify the other units that are required for this test. - // needs: ['serializer:foo'] -}); - -// Replace this with your real tests. -test('it exists', function(assert) { - let adapter = this.subject(); - assert.ok(adapter); -}); diff --git a/tests/unit/adapters/comment-test.js b/tests/unit/adapters/comment-test.js deleted file mode 100644 index 0f9aed191..000000000 --- a/tests/unit/adapters/comment-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('adapter:comment', 'Unit | Adapter | comment', { - // Specify the other units that are required for this test. - // needs: ['serializer:foo'] -}); - -// Replace this with your real tests. -test('it exists', function(assert) { - let adapter = this.subject(); - assert.ok(adapter); -}); diff --git a/tests/unit/adapters/contributor-test.js b/tests/unit/adapters/contributor-test.js deleted file mode 100644 index eed33c511..000000000 --- a/tests/unit/adapters/contributor-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('adapter:contributor', 'Unit | Adapter | contributor', { - // Specify the other units that are required for this test. - // needs: ['serializer:foo'] -}); - -// Replace this with your real tests. -test('it exists', function(assert) { - let adapter = this.subject(); - assert.ok(adapter); -}); diff --git a/tests/unit/adapters/institution-test.js b/tests/unit/adapters/institution-test.js deleted file mode 100644 index c19c9cbf6..000000000 --- a/tests/unit/adapters/institution-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('adapter:institution', 'Unit | Adapter | institution', { - // Specify the other units that are required for this test. - // needs: ['serializer:foo'] -}); - -// Replace this with your real tests. -test('it exists', function(assert) { - let adapter = this.subject(); - assert.ok(adapter); -}); diff --git a/tests/unit/adapters/registration-test.js b/tests/unit/adapters/registration-test.js deleted file mode 100644 index d65d14274..000000000 --- a/tests/unit/adapters/registration-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('adapter:registration', 'Unit | Adapter | registration', { - // Specify the other units that are required for this test. - // needs: ['serializer:foo'] -}); - -// Replace this with your real tests. -test('it exists', function(assert) { - let adapter = this.subject(); - assert.ok(adapter); -}); diff --git a/tests/unit/adapters/user-test.js b/tests/unit/adapters/user-test.js deleted file mode 100644 index 39da04368..000000000 --- a/tests/unit/adapters/user-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('adapter:user', 'Unit | Adapter | user', { - // Specify the other units that are required for this test. - // needs: ['serializer:foo'] -}); - -// Replace this with your real tests. -test('it exists', function(assert) { - let adapter = this.subject(); - assert.ok(adapter); -}); diff --git a/tests/unit/serializers/application-test.js b/tests/unit/serializers/application-test.js deleted file mode 100644 index 68df6a98a..000000000 --- a/tests/unit/serializers/application-test.js +++ /dev/null @@ -1,39 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; -import { faker } from 'ember-cli-mirage'; -// TODO: Move this to the osf-serializer tests file -moduleForModel('base', 'Unit | Serializer | application', { - needs: ['serializer:application'] -}); - -test('#_mergeFields adds links to attributes if included in payload', function(assert) { - let payload = { - id: faker.random.uuid(), - type: 'base', - attributes: { - key: 'value' - }, - links: { - html: faker.internet.url() - } - }; - let serializer = this.container.lookup('serializer:application'); - let normalized = serializer._mergeFields(payload); - assert.equal(normalized.attributes.links, payload.links); -}); -test('#_mergeFields adds embeds to attributes if included in payload', function(assert) { - let payload = { - id: faker.random.uuid(), - attributes: { - key: 'value' - }, - embeds: { - embedded: { - data: [faker.random.arrayElement()] - } - } - }; - let serializer = this.container.lookup('serializer:application'); - let normalized = serializer._mergeFields(payload); - - assert.equal(normalized.attributes.embeds, payload.embeds); -}); diff --git a/tests/unit/serializers/comment-report-test.js b/tests/unit/serializers/comment-report-test.js deleted file mode 100644 index d2facae37..000000000 --- a/tests/unit/serializers/comment-report-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('comment-report', 'Unit | Serializer | comment report', { - // Specify the other units that are required for this test. - needs: ['serializer:comment-report'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); diff --git a/tests/unit/serializers/comment-test.js b/tests/unit/serializers/comment-test.js deleted file mode 100644 index d254b0643..000000000 --- a/tests/unit/serializers/comment-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('comment', 'Unit | Serializer | comment', { - // Specify the other units that are required for this test. - needs: ['serializer:comment'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); diff --git a/tests/unit/serializers/contributor-test.js b/tests/unit/serializers/contributor-test.js deleted file mode 100644 index 65ea5b2dc..000000000 --- a/tests/unit/serializers/contributor-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('contributor', 'Unit | Serializer | contributor', { - // Specify the other units that are required for this test. - needs: ['serializer:contributor'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); diff --git a/tests/unit/serializers/institution-test.js b/tests/unit/serializers/institution-test.js deleted file mode 100644 index 538233783..000000000 --- a/tests/unit/serializers/institution-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('institution', 'Unit | Serializer | institution', { - // Specify the other units that are required for this test. - needs: ['serializer:institution'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); diff --git a/tests/unit/serializers/node-test.js b/tests/unit/serializers/node-test.js deleted file mode 100644 index b79ba7400..000000000 --- a/tests/unit/serializers/node-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('node', 'Unit | Serializer | node', { - // Specify the other units that are required for this test. - needs: ['serializer:node'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); diff --git a/tests/unit/serializers/osf-serializer-test.js b/tests/unit/serializers/osf-serializer-test.js index 7f17ed15d..1410cfcd2 100644 --- a/tests/unit/serializers/osf-serializer-test.js +++ b/tests/unit/serializers/osf-serializer-test.js @@ -1,15 +1,38 @@ import { moduleForModel, test } from 'ember-qunit'; - +import { faker } from 'ember-cli-mirage'; moduleForModel('osf-serializer', 'Unit | Serializer | osf serializer', { - // Specify the other units that are required for this test. needs: ['serializer:osf-serializer'] }); -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); +test('#_mergeFields adds links to attributes if included in payload', function(assert) { + let payload = { + id: faker.random.uuid(), + type: 'base', + attributes: { + key: 'value' + }, + links: { + html: faker.internet.url() + } + }; + let serializer = this.container.lookup('serializer:osf-serializer'); + let normalized = serializer._mergeFields(payload); + assert.equal(normalized.attributes.links, payload.links); +}); +test('#_mergeFields adds embeds to attributes if included in payload', function(assert) { + let payload = { + id: faker.random.uuid(), + attributes: { + key: 'value' + }, + embeds: { + embedded: { + data: [faker.random.arrayElement()] + } + } + }; + let serializer = this.container.lookup('serializer:osf-serializer'); + let normalized = serializer._mergeFields(payload); - assert.ok(serializedRecord); + assert.equal(normalized.attributes.embeds, payload.embeds); }); diff --git a/tests/unit/serializers/registration-test.js b/tests/unit/serializers/registration-test.js deleted file mode 100644 index 5df643972..000000000 --- a/tests/unit/serializers/registration-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('registration', 'Unit | Serializer | registration', { - // Specify the other units that are required for this test. - needs: ['serializer:registration'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); diff --git a/tests/unit/serializers/user-test.js b/tests/unit/serializers/user-test.js deleted file mode 100644 index 19e4a38d0..000000000 --- a/tests/unit/serializers/user-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('user', 'Unit | Serializer | user', { - // Specify the other units that are required for this test. - needs: ['serializer:user'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); From c29190a7f336fb7373fa4d212369eedd499a9e79 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 12 May 2016 14:27:52 -0400 Subject: [PATCH 123/959] Fix failing test --- addon/models/registration.js | 2 +- tests/unit/serializers/osf-serializer-test.js | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/addon/models/registration.js b/addon/models/registration.js index 82cd5fb9e..c57598432 100644 --- a/addon/models/registration.js +++ b/addon/models/registration.js @@ -1,6 +1,6 @@ import DS from 'ember-data'; -import Node from '../models/node'; +import Node from './node'; export default Node.extend({ dateRegistered: DS.attr('date'), diff --git a/tests/unit/serializers/osf-serializer-test.js b/tests/unit/serializers/osf-serializer-test.js index 1410cfcd2..283ee4313 100644 --- a/tests/unit/serializers/osf-serializer-test.js +++ b/tests/unit/serializers/osf-serializer-test.js @@ -1,8 +1,6 @@ -import { moduleForModel, test } from 'ember-qunit'; +import { moduleFor, test } from 'ember-qunit'; import { faker } from 'ember-cli-mirage'; -moduleForModel('osf-serializer', 'Unit | Serializer | osf serializer', { - needs: ['serializer:osf-serializer'] -}); +moduleFor('serializer:osf-serializer'); test('#_mergeFields adds links to attributes if included in payload', function(assert) { let payload = { From 076bd7c5f8babf667f4bac97f70c9dc92b569fe2 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 12 May 2016 16:22:07 -0400 Subject: [PATCH 124/959] Update with new models --- addon/adapters/file-contents.js | 4 ++++ addon/adapters/file-provider.js | 4 ++-- addon/adapters/file-version.js | 4 ++++ addon/adapters/file.js | 4 ++++ addon/models/file-contents.js | 7 +++---- addon/models/file-provider.js | 4 ++-- addon/models/file-version.js | 4 ++-- addon/models/file.js | 4 ++-- addon/serializers/file-contents.js | 4 ++++ addon/serializers/file-provider.js | 4 ++-- addon/serializers/file-version.js | 4 ++++ addon/serializers/file.js | 4 ++++ app/adapters/file-contents.js | 1 + app/adapters/file-version.js | 1 + app/adapters/file.js | 1 + app/serializers/file-contents.js | 1 + app/serializers/file-version.js | 1 + app/serializers/file.js | 1 + tests/unit/adapters/file-provider-test.js | 12 ------------ 19 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 addon/adapters/file-contents.js create mode 100644 addon/adapters/file-version.js create mode 100644 addon/adapters/file.js create mode 100644 addon/serializers/file-contents.js create mode 100644 addon/serializers/file-version.js create mode 100644 addon/serializers/file.js create mode 100644 app/adapters/file-contents.js create mode 100644 app/adapters/file-version.js create mode 100644 app/adapters/file.js create mode 100644 app/serializers/file-contents.js create mode 100644 app/serializers/file-version.js create mode 100644 app/serializers/file.js delete mode 100644 tests/unit/adapters/file-provider-test.js diff --git a/addon/adapters/file-contents.js b/addon/adapters/file-contents.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/file-contents.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/adapters/file-provider.js b/addon/adapters/file-provider.js index 1f527b735..6b2ebef26 100644 --- a/addon/adapters/file-provider.js +++ b/addon/adapters/file-provider.js @@ -1,6 +1,6 @@ -import ApplicationAdapter from './application'; +import OsfAdapter from './osf-adapter'; -export default ApplicationAdapter.extend({ +export default OsfAdapter.extend({ pathForType() { return 'files'; } diff --git a/addon/adapters/file-version.js b/addon/adapters/file-version.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/file-version.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/adapters/file.js b/addon/adapters/file.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/file.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/models/file-contents.js b/addon/models/file-contents.js index d3d7a8056..cf9ac6008 100644 --- a/addon/models/file-contents.js +++ b/addon/models/file-contents.js @@ -1,7 +1,6 @@ -//import DS from 'ember-data'; +import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from '../mixins/osf-model'; -export default OsfModel.extend({ - // TODO fetch file content from waterbutler +export default DS.Model.extend(OsfModel, { }); diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index ac66b3e9c..102b5afca 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -1,9 +1,9 @@ import Ember from 'ember'; import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from '../mixins/osf-model'; -export default OsfModel.extend({ +export default DS.Model.extend(OsfModel, { kind: DS.attr('string'), name: DS.attr('string'), path: DS.attr('string'), diff --git a/addon/models/file-version.js b/addon/models/file-version.js index 51165f08e..eef1228be 100644 --- a/addon/models/file-version.js +++ b/addon/models/file-version.js @@ -1,8 +1,8 @@ import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from '../mixins/osf-model'; -export default OsfModel.extend({ +export default DS.Model.extend(OsfModel, { size: DS.attr('number'), contentType: DS.attr('string'), }); diff --git a/addon/models/file.js b/addon/models/file.js index 625d07f13..adf57fe49 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -1,8 +1,8 @@ import Ember from 'ember'; import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from '../mixins/osf-model'; -export default OsfModel.extend({ +export default DS.Model.extend(OsfModel, { name: DS.attr('string'), kind: DS.attr('string'), path: DS.attr('string'), diff --git a/addon/serializers/file-contents.js b/addon/serializers/file-contents.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/file-contents.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/addon/serializers/file-provider.js b/addon/serializers/file-provider.js index 11d1cfeed..a4debf398 100644 --- a/addon/serializers/file-provider.js +++ b/addon/serializers/file-provider.js @@ -1,6 +1,6 @@ -import JSONAPISerializer from 'ember-data/serializers/json-api'; +import OsfSerializer from './osf-serializer'; -export default JSONAPISerializer.extend({ +export default OsfSerializer.extend({ modelNameFromPayloadKey() { return 'file-provider'; } diff --git a/addon/serializers/file-version.js b/addon/serializers/file-version.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/file-version.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/addon/serializers/file.js b/addon/serializers/file.js new file mode 100644 index 000000000..c5617e1d4 --- /dev/null +++ b/addon/serializers/file.js @@ -0,0 +1,4 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ +}); diff --git a/app/adapters/file-contents.js b/app/adapters/file-contents.js new file mode 100644 index 000000000..e23a8a2bc --- /dev/null +++ b/app/adapters/file-contents.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/file-contents'; diff --git a/app/adapters/file-version.js b/app/adapters/file-version.js new file mode 100644 index 000000000..3e9f5341b --- /dev/null +++ b/app/adapters/file-version.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/file-version'; diff --git a/app/adapters/file.js b/app/adapters/file.js new file mode 100644 index 000000000..7e19bd666 --- /dev/null +++ b/app/adapters/file.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/file'; diff --git a/app/serializers/file-contents.js b/app/serializers/file-contents.js new file mode 100644 index 000000000..46a8bb05b --- /dev/null +++ b/app/serializers/file-contents.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/file-contents'; diff --git a/app/serializers/file-version.js b/app/serializers/file-version.js new file mode 100644 index 000000000..e1e27b114 --- /dev/null +++ b/app/serializers/file-version.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/file-version'; diff --git a/app/serializers/file.js b/app/serializers/file.js new file mode 100644 index 000000000..5d4f751e4 --- /dev/null +++ b/app/serializers/file.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/file'; diff --git a/tests/unit/adapters/file-provider-test.js b/tests/unit/adapters/file-provider-test.js deleted file mode 100644 index 3fea566c9..000000000 --- a/tests/unit/adapters/file-provider-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('adapter:file-provider', 'Unit | Adapter | file provider', { - // Specify the other units that are required for this test. - // needs: ['serializer:foo'] -}); - -// Replace this with your real tests. -test('it exists', function(assert) { - let adapter = this.subject(); - assert.ok(adapter); -}); From d095c8a77e869ea6937bf804a0d2014821ae538a Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 12 May 2016 16:26:25 -0400 Subject: [PATCH 125/959] Quis custodiet ipsos custodes? (that said, `npm run check-style` is handy; thanks!) --- package.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 8ee38ab2f..0bb721a25 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build": "ember build", "start": "ember server", "test": "ember test", - "check-style": "./node_modules/jscs/bin/jscs ." + "check-style": "./node_modules/jscs/bin/jscs ." }, "repository": "", "engines": { @@ -66,14 +66,14 @@ "configPath": "tests/dummy/config" }, "jscsConfig": { - "preset": "airbnb", - "excludeFiles": ["bower_components", "dist", "tmp", "vendor", "app/locales", "tests/unit", "tests/integration", "tests/helpers", "tests/dummy/app/mirage"], - "requireSpacesInAnonymousFunctionExpression": false, - "requireTrailingComma": false, - "disallowTrailingComma": false, - "requirePaddingNewLinesAfterBlocks": false, - "validateIndentation": 4, - "requirePaddingNewLinesBeforeLineComments": false, - "maximumLineLength": false + "preset": "airbnb", + "excludeFiles": ["bower_components", "dist", "tmp", "vendor", "app/locales", "tests/unit", "tests/integration", "tests/helpers", "tests/dummy/app/mirage"], + "requireSpacesInAnonymousFunctionExpression": false, + "requireTrailingComma": false, + "disallowTrailingComma": false, + "requirePaddingNewLinesAfterBlocks": false, + "validateIndentation": 4, + "requirePaddingNewLinesBeforeLineComments": false, + "maximumLineLength": false } } From a8ab262012669eb0f87720b3beb4299074142588 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 17:07:38 -0400 Subject: [PATCH 126/959] Update table css. --- tests/dummy/app/styles/app.scss | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/dummy/app/styles/app.scss b/tests/dummy/app/styles/app.scss index 0549d9fb2..5e791012e 100644 --- a/tests/dummy/app/styles/app.scss +++ b/tests/dummy/app/styles/app.scss @@ -1,8 +1,7 @@ -table { - border-collapse: separate; - border-spacing: 5px 0; -} - -td { - padding: 10px 0; +table.logs, table.logs th, table.logs td { + border: 1px solid black; + border-collapse: collapse; + border-spacing: 10px 5px; + text-align: center; + padding: 5px 10px; } From ec08f41e714e269ada8b762a1f631db55a209412 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 17:08:16 -0400 Subject: [PATCH 127/959] Turn log detail into a component that can be used in both registration and node detail pages. --- .../app/templates/components/log-detail.hbs | 25 +++++++++++++++++++ tests/dummy/app/templates/nodes/detail.hbs | 16 ++---------- .../app/templates/registrations/detail.hbs | 15 +---------- 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 tests/dummy/app/templates/components/log-detail.hbs diff --git a/tests/dummy/app/templates/components/log-detail.hbs b/tests/dummy/app/templates/components/log-detail.hbs new file mode 100644 index 000000000..38716ea0a --- /dev/null +++ b/tests/dummy/app/templates/components/log-detail.hbs @@ -0,0 +1,25 @@ +

Recent Activity

+ + + + + + + + + + + {{#each node-logs as |node-log|}} + + + + + + + + + {{/each}} +
Action Original Node User Current Node Date Additional Params Included
{{node-log.action}} {{node-log.originalNode.id}} {{node-log.user.givenName}} {{node-log.node.id}} {{moment-format node-log.date}} {{#each-in node-log.params as |key value|}} + {{key}}, + {{/each-in}} +
diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index aa2707f98..d0698de42 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -43,20 +43,8 @@

-

Recent Activity

- - {{#each model.logs as |node-log|}} - - - - - - - - - - {{/each}} -
{{node-log.action}} for {{node-log.originalNode.id}} by {{node-log.user.givenName}} on {{moment-format node-log.date}}
+ {{log-detail node-logs=model.logs}} +

Files

{{#each model.files as |provider|}} {{files-tree model=provider}} diff --git a/tests/dummy/app/templates/registrations/detail.hbs b/tests/dummy/app/templates/registrations/detail.hbs index 0465e1b08..780ea6fbf 100644 --- a/tests/dummy/app/templates/registrations/detail.hbs +++ b/tests/dummy/app/templates/registrations/detail.hbs @@ -12,19 +12,6 @@

{{link-to 'Node Registered' 'nodes.detail' model.registeredFrom.id class="btn btn-warning"}}

-

Recent Activity

- - {{#each model.logs as |node-log|}} - - - - - - - - - - {{/each}} -
{{node-log.action}} for {{node-log.originalNode.id}} by {{node-log.user.givenName}} on {{moment-format node-log.date}}
+ {{log-detail node-logs=model.logs}}
From 4ec2a422eddc97233b2ced3b81b6678f7d54e73b Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 17:33:32 -0400 Subject: [PATCH 128/959] Add links to items in logs. --- tests/dummy/app/templates/components/log-detail.hbs | 6 +++--- tests/dummy/app/templates/nodes/detail.hbs | 5 +++-- tests/dummy/app/templates/registrations/detail.hbs | 2 +- tests/unit/models/node-test.js | 2 +- tests/unit/models/registration-test.js | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/dummy/app/templates/components/log-detail.hbs b/tests/dummy/app/templates/components/log-detail.hbs index 38716ea0a..ced12e41c 100644 --- a/tests/dummy/app/templates/components/log-detail.hbs +++ b/tests/dummy/app/templates/components/log-detail.hbs @@ -12,9 +12,9 @@ {{#each node-logs as |node-log|}} {{node-log.action}} - {{node-log.originalNode.id}} - {{node-log.user.givenName}} - {{node-log.node.id}} + {{node-log.originalNode.title}}: {{node-log.originalNode.id}} + {{node-log.user.givenName}} + {{node-log.node.title}}: {{node-log.node.id}} {{moment-format node-log.date}} {{#each-in node-log.params as |key value|}} {{key}}, diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index d0698de42..bdee11b0d 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -43,10 +43,11 @@

- {{log-detail node-logs=model.logs}} -

Files

{{#each model.files as |provider|}} {{files-tree model=provider}} {{/each}} +
+ + {{log-detail node-logs=model.logs}}
diff --git a/tests/dummy/app/templates/registrations/detail.hbs b/tests/dummy/app/templates/registrations/detail.hbs index 780ea6fbf..48ed6700a 100644 --- a/tests/dummy/app/templates/registrations/detail.hbs +++ b/tests/dummy/app/templates/registrations/detail.hbs @@ -12,6 +12,6 @@

{{link-to 'Node Registered' 'nodes.detail' model.registeredFrom.id class="btn btn-warning"}}

+
{{log-detail node-logs=model.logs}} -
diff --git a/tests/unit/models/node-test.js b/tests/unit/models/node-test.js index 1b1a5a13f..79a5a8add 100644 --- a/tests/unit/models/node-test.js +++ b/tests/unit/models/node-test.js @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('node', 'Unit | Model | node', { // Specify the other units that are required for this test. - needs: ['model:user', 'model:contributor', 'model:comment', 'model:institution', 'model:registration', 'model:file-provider'] + needs: ['model:user', 'model:contributor', 'model:comment', 'model:institution', 'model:registration', 'model:file-provider', 'model:log'] }); test('it exists', function(assert) { diff --git a/tests/unit/models/registration-test.js b/tests/unit/models/registration-test.js index a1230f67b..fd5fd377e 100644 --- a/tests/unit/models/registration-test.js +++ b/tests/unit/models/registration-test.js @@ -5,7 +5,7 @@ import { moduleForModel('registration', 'Unit | Model | registration', { // Specify the other units that are required for this test. - needs: ['model:institution', 'model:node', 'model:user', 'model:contributor', 'model:comment', 'model:file-provider'] + needs: ['model:institution', 'model:node', 'model:user', 'model:contributor', 'model:comment', 'model:file-provider', 'model:log'] }); test('it exists', function(assert) { From 217b915b88e2da13b073278d239dfb37cde3ab1a Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 12 May 2016 20:21:34 -0400 Subject: [PATCH 129/959] Add linked_node and template_node to logs. --- addon/models/log.js | 6 ++++-- tests/dummy/app/templates/components/log-detail.hbs | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/addon/models/log.js b/addon/models/log.js index 78290e66c..f8a41938b 100644 --- a/addon/models/log.js +++ b/addon/models/log.js @@ -12,8 +12,10 @@ export default OsfModel.extend({ inverse: 'logs' }), user: DS.belongsTo('user'), - linked_node: DS.belongsTo('node'), + linkedNode: DS.belongsTo('node', { + inverse: null + }), templateNode: DS.belongsTo('node', { - inverse: 'templateFrom' + inverse: null }) }); diff --git a/tests/dummy/app/templates/components/log-detail.hbs b/tests/dummy/app/templates/components/log-detail.hbs index ced12e41c..74a08ab78 100644 --- a/tests/dummy/app/templates/components/log-detail.hbs +++ b/tests/dummy/app/templates/components/log-detail.hbs @@ -19,6 +19,8 @@ {{#each-in node-log.params as |key value|}} {{key}}, {{/each-in}} + {{if node-log.linkedNode "linked_node"}} + {{if node-log.templateNode "template_node"}} {{/each}} From bc99a56424cce5d37102c05f4a60d9a0bf4fcf6b Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 13 May 2016 09:44:22 -0400 Subject: [PATCH 130/959] Change structure of log-detail component to include specific style file. --- tests/dummy/app/components/log-detail/style.css | 7 +++++++ .../log-detail.hbs => components/log-detail/template.hbs} | 0 2 files changed, 7 insertions(+) create mode 100644 tests/dummy/app/components/log-detail/style.css rename tests/dummy/app/{templates/components/log-detail.hbs => components/log-detail/template.hbs} (100%) diff --git a/tests/dummy/app/components/log-detail/style.css b/tests/dummy/app/components/log-detail/style.css new file mode 100644 index 000000000..5e791012e --- /dev/null +++ b/tests/dummy/app/components/log-detail/style.css @@ -0,0 +1,7 @@ +table.logs, table.logs th, table.logs td { + border: 1px solid black; + border-collapse: collapse; + border-spacing: 10px 5px; + text-align: center; + padding: 5px 10px; +} diff --git a/tests/dummy/app/templates/components/log-detail.hbs b/tests/dummy/app/components/log-detail/template.hbs similarity index 100% rename from tests/dummy/app/templates/components/log-detail.hbs rename to tests/dummy/app/components/log-detail/template.hbs From 49007dec7762d529067b2f99068d05240fbac205 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 13 May 2016 09:44:36 -0400 Subject: [PATCH 131/959] Remove primary_institution from log model. --- .gitignore | 1 - addon/models/node.js | 1 - 2 files changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 309abf092..f3e1637c8 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,3 @@ npm-debug.log testem.log config/*.yml -.idea/ diff --git a/addon/models/node.js b/addon/models/node.js index 00cfbfe3f..1d8d8c59b 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -43,6 +43,5 @@ export default OsfModel.extend({ root: DS.belongsTo('node', { inverse: null }), - //primaryInstitution: DS.belongsTo('institution'), logs: DS.hasMany('logs') }); From 966ae9da6094eb453ca3eef898abc45338146ce3 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 13 May 2016 10:04:46 -0400 Subject: [PATCH 132/959] Remove styling from app.scss. --- tests/dummy/app/styles/app.scss | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/dummy/app/styles/app.scss b/tests/dummy/app/styles/app.scss index 5e791012e..e69de29bb 100644 --- a/tests/dummy/app/styles/app.scss +++ b/tests/dummy/app/styles/app.scss @@ -1,7 +0,0 @@ -table.logs, table.logs th, table.logs td { - border: 1px solid black; - border-collapse: collapse; - border-spacing: 10px 5px; - text-align: center; - padding: 5px 10px; -} From 3f4c34a1d2e555e91d4326a9b18b296dce3ff2df Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 13 May 2016 10:14:01 -0400 Subject: [PATCH 133/959] Use relative import and extend DS.Model in models/log.js. --- addon/models/log.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/models/log.js b/addon/models/log.js index f8a41938b..19cffb7f8 100644 --- a/addon/models/log.js +++ b/addon/models/log.js @@ -1,7 +1,7 @@ import DS from 'ember-data'; -import OsfModel from 'ember-osf/models/base'; +import OsfModel from '../mixins/osf-model'; -export default OsfModel.extend({ +export default DS.Model.extend(OsfModel, { date: DS.attr('date'), action: DS.attr('string'), params: DS.attr(), From e96bebf4ccebcf26763a8deab6b61e7a0285b913 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 13 May 2016 11:41:35 -0400 Subject: [PATCH 134/959] Add ember-radio-button to dependencies. --- package.json | 164 +++++++++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 76 deletions(-) diff --git a/package.json b/package.json index 0bb721a25..946544cbb 100644 --- a/package.json +++ b/package.json @@ -1,79 +1,91 @@ { - "name": "ember-osf", - "version": "0.0.1", - "description": "Ember Data models for the OSF APIv2", - "directories": { - "doc": "doc", - "test": "tests" - }, - "scripts": { - "build": "ember build", - "start": "ember server", - "test": "ember test", - "check-style": "./node_modules/jscs/bin/jscs ." - }, - "repository": "", - "engines": { - "node": ">= 0.10.0" - }, - "author": "", - "license": "MIT", - "devDependencies": { - "broccoli-asset-rev": "^2.2.0", - "ember-a11y": "0.1.8", - "ember-a11y-testing": "0.0.5", - "ember-ajax": "0.7.1", - "ember-cli": "^2.4.3", - "ember-cli-app-version": "^1.0.0", - "ember-cli-dependency-checker": "^1.2.0", - "ember-cli-htmlbars": "^1.0.1", - "ember-cli-htmlbars-inline-precompile": "^0.3.1", - "ember-cli-inject-live-reload": "^1.3.1", - "ember-cli-mirage": "0.1.13", - "ember-cli-qunit": "^1.2.1", - "ember-cli-release": "0.2.8", - "ember-cli-sass": "5.3.1", - "ember-cli-sri": "^2.0.0", - "ember-cli-uglify": "^1.2.0", - "ember-data": "^2.3.0", - "ember-disable-prototype-extensions": "^1.0.0", - "ember-disable-proxy-controllers": "^1.0.1", - "ember-export-application-global": "^1.0.4", - "ember-i18n": "4.2.1", - "ember-load-initializers": "0.5.1", - "ember-resolver": "2.0.3", - "ember-sinon": "0.5.0", - "ember-sinon-qunit": "1.3.1", - "jscs": "^3.0.3", - "loader": "2.1.0", - "loader.js": "4.0.3", - "moment": "^2.13.0" - }, - "keywords": [ - "ember-addon" + "name": "ember-osf", + "version": "0.0.1", + "description": "Ember Data models for the OSF APIv2", + "directories": { + "doc": "doc", + "test": "tests" + }, + "scripts": { + "build": "ember build", + "start": "ember server", + "test": "ember test", + "check-style": "./node_modules/jscs/bin/jscs ." + }, + "repository": "", + "engines": { + "node": ">= 0.10.0" + }, + "author": "", + "license": "MIT", + "devDependencies": { + "broccoli-asset-rev": "^2.2.0", + "ember-a11y": "0.1.8", + "ember-a11y-testing": "0.0.5", + "ember-ajax": "0.7.1", + "ember-cli": "^2.4.3", + "ember-cli-app-version": "^1.0.0", + "ember-cli-dependency-checker": "^1.2.0", + "ember-cli-htmlbars": "^1.0.1", + "ember-cli-htmlbars-inline-precompile": "^0.3.1", + "ember-cli-inject-live-reload": "^1.3.1", + "ember-cli-mirage": "0.1.13", + "ember-cli-qunit": "^1.2.1", + "ember-cli-release": "0.2.8", + "ember-cli-sass": "5.3.1", + "ember-cli-sri": "^2.0.0", + "ember-cli-uglify": "^1.2.0", + "ember-data": "^2.3.0", + "ember-disable-prototype-extensions": "^1.0.0", + "ember-disable-proxy-controllers": "^1.0.1", + "ember-export-application-global": "^1.0.4", + "ember-i18n": "4.2.1", + "ember-load-initializers": "0.5.1", + "ember-radio-button": "1.0.7", + "ember-resolver": "2.0.3", + "ember-sinon": "0.5.0", + "ember-sinon-qunit": "1.3.1", + "jscs": "^3.0.3", + "loader": "2.1.0", + "loader.js": "4.0.3", + "moment": "^2.13.0" + }, + "keywords": [ + "ember-addon" + ], + "dependencies": { + "config": "^1.20.1", + "ember-cli-babel": "^5.1.5", + "ember-cli-moment-shim": "1.1.0", + "ember-cli-node-assets": "^0.1.3", + "ember-get-config": "0.0.2", + "ember-moment": "6.1.0", + "ember-radio-buttons": "^4.0.1", + "ember-simple-auth": "1.1.0-beta.5", + "js-yaml": "^3.6.0" + }, + "ember-addon": { + "configPath": "tests/dummy/config" + }, + "jscsConfig": { + "preset": "airbnb", + "excludeFiles": [ + "bower_components", + "dist", + "tmp", + "vendor", + "app/locales", + "tests/unit", + "tests/integration", + "tests/helpers", + "tests/dummy/app/mirage" ], - "dependencies": { - "config": "^1.20.1", - "ember-cli-babel": "^5.1.5", - "ember-cli-moment-shim": "1.1.0", - "ember-cli-node-assets": "^0.1.3", - "ember-get-config": "0.0.2", - "ember-moment": "6.1.0", - "ember-simple-auth": "1.1.0-beta.5", - "js-yaml": "^3.6.0" - }, - "ember-addon": { - "configPath": "tests/dummy/config" - }, - "jscsConfig": { - "preset": "airbnb", - "excludeFiles": ["bower_components", "dist", "tmp", "vendor", "app/locales", "tests/unit", "tests/integration", "tests/helpers", "tests/dummy/app/mirage"], - "requireSpacesInAnonymousFunctionExpression": false, - "requireTrailingComma": false, - "disallowTrailingComma": false, - "requirePaddingNewLinesAfterBlocks": false, - "validateIndentation": 4, - "requirePaddingNewLinesBeforeLineComments": false, - "maximumLineLength": false - } + "requireSpacesInAnonymousFunctionExpression": false, + "requireTrailingComma": false, + "disallowTrailingComma": false, + "requirePaddingNewLinesAfterBlocks": false, + "validateIndentation": 4, + "requirePaddingNewLinesBeforeLineComments": false, + "maximumLineLength": false + } } From 4b9abaa8f5afc2ef5a87d155dd008186512e0d98 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 13 May 2016 11:42:26 -0400 Subject: [PATCH 135/959] Add ability to edit category and description. --- tests/dummy/app/routes/nodes/detail.js | 9 ++++-- tests/dummy/app/templates/nodes/detail.hbs | 32 ++++++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index e1ea35f24..0948e6a6a 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -11,12 +11,15 @@ export default Ember.Route.extend({ }, actions: { - editExisting(value) { + editExisting(title, description, category) { // TODO: Should test PUT or PATCH - console.log('Will edit title from', this.modelFor(this.routeName).get('title'), ' to ', value); + // console.log('Will edit title from', this.modelFor(this.routeName).get('title'), ' to ', value); var node = this.modelFor(this.routeName); if (node.get('currentUserPermissions').indexOf('write') !== -1) { - node.set('title', value); + console.log(title, category, description, this.routeName); + if (title) {node.set('title', title);} + if (category) {node.set('category', category);} + if (description) {node.set('description', description);} node.save(); } else { console.log('You do not have permissions to edit this node'); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 0172728c6..3c257cf11 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -3,6 +3,7 @@

Data

{{model.title}}

+

{{model.description}}

{{model.category}}

{{moment-format model.dateCreated}}

{{moment-format model.dateModified}}

@@ -14,8 +15,35 @@

Edit this node

- Title: {{input value=editedTitle}} - + + + + + + + + + + +
Title: {{input value=editedTitle}}
Description: {{input value=editedDescription}}
+ +

Category:

+
+ {{radio-button name="category" value="analysis" checked=editedCategory}} Analysis
+ {{radio-button name="category" value="communication" checked=editedCategory}} Communication
+ {{radio-button name="category" value="data" checked=editedCategory}} Data
+ {{radio-button name="category" value="hypothesis" checked=editedCategory}} Hypothesis
+ {{radio-button name="category" value="instrumentation" checked=editedCategory}} Instrumentation
+ {{radio-button name="category" value="methods and measures" checked=editedCategory}} Methods and Measures
+ {{radio-button name="category" value="procedure" checked=editedCategory}} Procedure
+ {{radio-button name="category" value="project" checked=editedCategory}} Project
+ {{radio-button name="category" value="software" checked=editedCategory}} Software
+ {{radio-button name="category" value="other" checked=editedCategory}} Other
+ {{radio-button name="category" value="uncategorized" checked=editedCategory}} Uncategorized
+
+
+ +

Contributors

From 22c409872c6ec14943330f4ab1b12e139f38628e Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 13 May 2016 12:31:00 -0400 Subject: [PATCH 136/959] Consolidate node settings under "Edit node settings" button. --- tests/dummy/app/controllers/nodes/detail.js | 9 ++++ tests/dummy/app/routes/nodes/detail.js | 2 + tests/dummy/app/templates/nodes/detail.hbs | 58 +++++++++++---------- 3 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 tests/dummy/app/controllers/nodes/detail.js diff --git a/tests/dummy/app/controllers/nodes/detail.js b/tests/dummy/app/controllers/nodes/detail.js new file mode 100644 index 000000000..583e4f57d --- /dev/null +++ b/tests/dummy/app/controllers/nodes/detail.js @@ -0,0 +1,9 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + actions: { + expandProperties() { + this.toggleProperty('propertiesVisible'); + } + } +}); diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 0948e6a6a..f84c15469 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -7,6 +7,8 @@ export default Ember.Route.extend({ setupController(controller, model) { controller.set('editedTitle', model.get('title')); + controller.set('editedTitle', model.get('category')); + controller.set('editedTitle', model.get('dscription')); this._super(...arguments); }, diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 94a60a93f..ad892f006 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -14,37 +14,41 @@


-

Edit this node

- - - - - + {{#if propertiesVisible}} + +
Title: {{input value=editedTitle}}
+ + + + - - - - -
Title: {{input value=editedTitle}}
Description: {{input value=editedDescription}}
+ + Description: + {{input value=editedDescription}} + + -

Category:

-
- {{radio-button name="category" value="analysis" checked=editedCategory}} Analysis
- {{radio-button name="category" value="communication" checked=editedCategory}} Communication
- {{radio-button name="category" value="data" checked=editedCategory}} Data
- {{radio-button name="category" value="hypothesis" checked=editedCategory}} Hypothesis
- {{radio-button name="category" value="instrumentation" checked=editedCategory}} Instrumentation
- {{radio-button name="category" value="methods and measures" checked=editedCategory}} Methods and Measures
- {{radio-button name="category" value="procedure" checked=editedCategory}} Procedure
- {{radio-button name="category" value="project" checked=editedCategory}} Project
- {{radio-button name="category" value="software" checked=editedCategory}} Software
- {{radio-button name="category" value="other" checked=editedCategory}} Other
- {{radio-button name="category" value="uncategorized" checked=editedCategory}} Uncategorized
-
-
+

Category:

+
+ {{radio-button name="category" value="analysis" checked=editedCategory}} Analysis
+ {{radio-button name="category" value="communication" checked=editedCategory}} Communication
+ {{radio-button name="category" value="data" checked=editedCategory}} Data
+ {{radio-button name="category" value="hypothesis" checked=editedCategory}} Hypothesis
+ {{radio-button name="category" value="instrumentation" checked=editedCategory}} Instrumentation
+ {{radio-button name="category" value="methods and measures" checked=editedCategory}} Methods and Measures
+ {{radio-button name="category" value="procedure" checked=editedCategory}} Procedure
+ {{radio-button name="category" value="project" checked=editedCategory}} Project
+ {{radio-button name="category" value="software" checked=editedCategory}} Software
+ {{radio-button name="category" value="other" checked=editedCategory}} Other
+ {{radio-button name="category" value="uncategorized" checked=editedCategory}} Uncategorized
+
+
- + + {{else}} + + {{/if}}

Contributors

From d3cefda8e552097230e11c279cfbb3b0dc8ddfb5 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 13 May 2016 13:11:59 -0400 Subject: [PATCH 137/959] Add file-manager service to encapsulate waterbutler --- addon/services/file-manager.js | 4 ++++ app/services/file-manager.js | 1 + tests/unit/services/file-manager-test.js | 12 ++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 addon/services/file-manager.js create mode 100644 app/services/file-manager.js create mode 100644 tests/unit/services/file-manager-test.js diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js new file mode 100644 index 000000000..b9261c61d --- /dev/null +++ b/addon/services/file-manager.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Service.extend({ +}); diff --git a/app/services/file-manager.js b/app/services/file-manager.js new file mode 100644 index 000000000..0cbb07dc6 --- /dev/null +++ b/app/services/file-manager.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/services/file-manager'; diff --git a/tests/unit/services/file-manager-test.js b/tests/unit/services/file-manager-test.js new file mode 100644 index 000000000..f01138a66 --- /dev/null +++ b/tests/unit/services/file-manager-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('service:file-manager', 'Unit | Service | file manager', { + // Specify the other units that are required for this test. + // needs: ['service:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let service = this.subject(); + assert.ok(service); +}); From 7e5333672e16c66682f7b672e7e380cb3c0b57e1 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 13 May 2016 13:40:13 -0400 Subject: [PATCH 138/959] Upgrade ember-cli-mirage and small fixes - add CATEGORY_MAP constant to Node model - fix Institution.users relationship - add permissions constansts --- addon/const/permissions.js | 12 ++++++++++++ addon/models/institution.js | 2 +- addon/models/node.js | 14 ++++++++++++++ bower.json | 2 +- index.js | 10 +++++----- package.json | 14 ++++++++++++-- tests/helpers/destroy-app.js | 1 + 7 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 addon/const/permissions.js diff --git a/addon/const/permissions.js b/addon/const/permissions.js new file mode 100644 index 000000000..1a93bb069 --- /dev/null +++ b/addon/const/permissions.js @@ -0,0 +1,12 @@ +var ADMIN = 'admin'; +var READ = 'read'; +var WRITE = 'write'; + +export default { + ADMIN: ADMIN, + READ: READ, + WRITE: WRITE, + PERMISSIONS: [READ, WRITE, ADMIN], + CREATOR_PERMISSIONS: [READ, WRITE, ADMIN], + DEFAULT_CONTRIBUTOR_PERMISSIONS: [READ, WRITE] +}; diff --git a/addon/models/institution.js b/addon/models/institution.js index c5ccd1614..0f6130f7b 100644 --- a/addon/models/institution.js +++ b/addon/models/institution.js @@ -8,7 +8,7 @@ export default DS.Model.extend(OsfModel, { logoPath: DS.attr('string'), authUrl: DS.attr('string'), - children: DS.hasMany('users', { + users: DS.hasMany('users', { inverse: 'affiliatedInstitutions' }), nodes: DS.hasMany('nodes', { diff --git a/addon/models/node.js b/addon/models/node.js index b184a619c..311dfc75d 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -3,6 +3,20 @@ import DS from 'ember-data'; import OsfModel from '../mixins/osf-model'; export default DS.Model.extend(OsfModel, { + CATEGORY_MAP: { + analysis: 'Analysis', + communication: 'Communication', + data: 'Data', + hypothesis: 'Hypothesis', + instrumentation: 'Instrumentation', + 'methods and measures': 'Methods and Measures', + procedure: 'Procedure', + project: 'Project', + software: 'Software', + other: 'Other', + '': 'Uncategorized' + }, + title: DS.attr('string'), description: DS.attr('string'), category: DS.attr('string'), diff --git a/bower.json b/bower.json index c435c94aa..3bb49e852 100644 --- a/bower.json +++ b/bower.json @@ -6,7 +6,7 @@ "ember-cli-test-loader": "0.2.1", "ember-qunit-notifications": "0.1.0", "Faker": "~3.0.0", - "pretender": "~0.10.1", + "pretender": "~0.12.0", "lodash": "~3.7.0" }, "devDependencies": { diff --git a/index.js b/index.js index c28960264..fbf695471 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ module.exports = { apiNamespace: 'v2' // URL suffix (after host) }; - if (BACKEND === 'local') { + if (BACKEND === 'local' || environment === 'test') { ENV.OSF.url = 'http://localhost:5000/'; ENV.OSF.apiUrl = 'http://localhost:8000'; ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; @@ -31,22 +31,22 @@ module.exports = { ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; ENV.OSF.isLocal = true; } - if (BACKEND === 'stage') { + else if (BACKEND === 'stage') { ENV.OSF.url = 'https://staging.osf.io/'; ENV.OSF.apiUrl = 'https://staging-api.osf.io'; ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; } - if (BACKEND === 'stage2') { + else if (BACKEND === 'stage2') { ENV.OSF.url = 'https://staging2.osf.io/'; ENV.OSF.apiUrl = 'https://staging2-api.osf.io'; ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; } - if (BACKEND === 'test') { + else if (BACKEND === 'test') { ENV.OSF.url = 'https://test.osf.io/'; ENV.OSF.apiUrl = 'https://test-api.osf.io'; ENV.OSF.authUrl = 'https://test-accounts.osf.io/oauth2/authorize'; } - if (BACKEND === 'prod') { + else if (BACKEND === 'prod') { console.log(`WARNING: you\'ve specified production as a backend. Please do not use production for testing or development purposes`); ENV.OSF.url = 'https://osf.io/'; ENV.OSF.apiUrl = 'https://api.osf.io'; diff --git a/package.json b/package.json index 0bb721a25..b48dd0cf1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build": "ember build", "start": "ember server", "test": "ember test", - "check-style": "./node_modules/jscs/bin/jscs ." + "check-style": "./node_modules/jscs/bin/jscs ." }, "repository": "", "engines": { @@ -67,7 +67,17 @@ }, "jscsConfig": { "preset": "airbnb", - "excludeFiles": ["bower_components", "dist", "tmp", "vendor", "app/locales", "tests/unit", "tests/integration", "tests/helpers", "tests/dummy/app/mirage"], + "excludeFiles": [ + "bower_components", + "dist", + "tmp", + "vendor", + "app/locales", + "tests/unit", + "tests/integration", + "tests/helpers", + "tests/dummy/app/mirage" + ], "requireSpacesInAnonymousFunctionExpression": false, "requireTrailingComma": false, "disallowTrailingComma": false, diff --git a/tests/helpers/destroy-app.js b/tests/helpers/destroy-app.js index c3d4d1abb..3a0114aae 100644 --- a/tests/helpers/destroy-app.js +++ b/tests/helpers/destroy-app.js @@ -2,4 +2,5 @@ import Ember from 'ember'; export default function destroyApp(application) { Ember.run(application, 'destroy'); + server.shutdown(); } From 05d2260710da21fa1bc29fca73793066c5eae92c Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 13 May 2016 13:42:35 -0400 Subject: [PATCH 139/959] WIP adding mirage factories/models --- app/mirage-factories/contributor.js | 1 + app/mirage-factories/institution.js | 1 + app/mirage-factories/log.js | 1 + app/mirage-factories/node.js | 1 + app/mirage-factories/registration.js | 1 + app/mirage-factories/user.js | 1 + app/mirage-models/contributor.js | 1 + app/mirage-models/institutions.js | 1 + app/mirage-models/logs.js | 1 + app/mirage-models/node.js | 1 + app/mirage-models/registration.js | 1 + app/mirage-models/user.js | 1 + tests/dummy/mirage/config.js | 48 +++++++++++++++++++ tests/dummy/mirage/factories/contributor.js | 17 +++++++ tests/dummy/mirage/factories/institution.js | 5 ++ tests/dummy/mirage/factories/log.js | 5 ++ tests/dummy/mirage/factories/node.js | 42 ++++++++++++++++ tests/dummy/mirage/factories/registration.js | 45 +++++++++++++++++ tests/dummy/mirage/factories/user.js | 14 ++++++ tests/dummy/mirage/models/contributor.js | 8 ++++ tests/dummy/mirage/models/institutions.js | 16 +++++++ tests/dummy/mirage/models/logs.js | 12 +++++ tests/dummy/mirage/models/node.js | 26 ++++++++++ tests/dummy/mirage/models/registration.js | 13 +++++ tests/dummy/mirage/models/user.js | 12 +++++ tests/dummy/mirage/scenarios/default.js | 11 +++++ tests/dummy/mirage/serializers/application.js | 4 ++ tests/dummy/mirage/util.js | 7 +++ 28 files changed, 297 insertions(+) create mode 100644 app/mirage-factories/contributor.js create mode 100644 app/mirage-factories/institution.js create mode 100644 app/mirage-factories/log.js create mode 100644 app/mirage-factories/node.js create mode 100644 app/mirage-factories/registration.js create mode 100644 app/mirage-factories/user.js create mode 100644 app/mirage-models/contributor.js create mode 100644 app/mirage-models/institutions.js create mode 100644 app/mirage-models/logs.js create mode 100644 app/mirage-models/node.js create mode 100644 app/mirage-models/registration.js create mode 100644 app/mirage-models/user.js create mode 100644 tests/dummy/mirage/config.js create mode 100644 tests/dummy/mirage/factories/contributor.js create mode 100644 tests/dummy/mirage/factories/institution.js create mode 100644 tests/dummy/mirage/factories/log.js create mode 100644 tests/dummy/mirage/factories/node.js create mode 100644 tests/dummy/mirage/factories/registration.js create mode 100644 tests/dummy/mirage/factories/user.js create mode 100644 tests/dummy/mirage/models/contributor.js create mode 100644 tests/dummy/mirage/models/institutions.js create mode 100644 tests/dummy/mirage/models/logs.js create mode 100644 tests/dummy/mirage/models/node.js create mode 100644 tests/dummy/mirage/models/registration.js create mode 100644 tests/dummy/mirage/models/user.js create mode 100644 tests/dummy/mirage/scenarios/default.js create mode 100644 tests/dummy/mirage/serializers/application.js create mode 100644 tests/dummy/mirage/util.js diff --git a/app/mirage-factories/contributor.js b/app/mirage-factories/contributor.js new file mode 100644 index 000000000..3249bd653 --- /dev/null +++ b/app/mirage-factories/contributor.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-factories/contributor'; diff --git a/app/mirage-factories/institution.js b/app/mirage-factories/institution.js new file mode 100644 index 000000000..0c5770ae7 --- /dev/null +++ b/app/mirage-factories/institution.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-factories/institution'; diff --git a/app/mirage-factories/log.js b/app/mirage-factories/log.js new file mode 100644 index 000000000..52ca0ef07 --- /dev/null +++ b/app/mirage-factories/log.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-factories/log'; diff --git a/app/mirage-factories/node.js b/app/mirage-factories/node.js new file mode 100644 index 000000000..10a7cd899 --- /dev/null +++ b/app/mirage-factories/node.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-factories/node'; diff --git a/app/mirage-factories/registration.js b/app/mirage-factories/registration.js new file mode 100644 index 000000000..df76bfa89 --- /dev/null +++ b/app/mirage-factories/registration.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-factories/registration'; diff --git a/app/mirage-factories/user.js b/app/mirage-factories/user.js new file mode 100644 index 000000000..02d727f56 --- /dev/null +++ b/app/mirage-factories/user.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-factories/user'; diff --git a/app/mirage-models/contributor.js b/app/mirage-models/contributor.js new file mode 100644 index 000000000..bd70b6526 --- /dev/null +++ b/app/mirage-models/contributor.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-models/contributor'; diff --git a/app/mirage-models/institutions.js b/app/mirage-models/institutions.js new file mode 100644 index 000000000..ebb7882dd --- /dev/null +++ b/app/mirage-models/institutions.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-models/institutions'; diff --git a/app/mirage-models/logs.js b/app/mirage-models/logs.js new file mode 100644 index 000000000..04c1295a8 --- /dev/null +++ b/app/mirage-models/logs.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-models/logs'; diff --git a/app/mirage-models/node.js b/app/mirage-models/node.js new file mode 100644 index 000000000..02a453a5e --- /dev/null +++ b/app/mirage-models/node.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-models/node'; diff --git a/app/mirage-models/registration.js b/app/mirage-models/registration.js new file mode 100644 index 000000000..e1af39942 --- /dev/null +++ b/app/mirage-models/registration.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-models/registration'; diff --git a/app/mirage-models/user.js b/app/mirage-models/user.js new file mode 100644 index 000000000..da6828fac --- /dev/null +++ b/app/mirage-models/user.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/mirage-models/user'; diff --git a/tests/dummy/mirage/config.js b/tests/dummy/mirage/config.js new file mode 100644 index 000000000..799a0c4b5 --- /dev/null +++ b/tests/dummy/mirage/config.js @@ -0,0 +1,48 @@ +export default function() { + + // These comments are here to help you get started. Feel free to delete them. + + /* + Config (with defaults). + + Note: these only affect routes defined *after* them! + */ + + this.urlPrefix = 'http://localhost:8000'; + this.namespace = 'v2'; + // this.timing = 400; // delay for each request, automatically set to 0 during testing + + this.get('/users/', (schema) => schema.user.all()); + this.get('/users/:id/', (schema, request) => schema.user.find(request.params.id)); + this.get('/users/:id/nodes', (schema, request) => schema.user.find(request.params.id).nodes.all()); + this.get('/users/:id/relationships/institutions/', (schema, request) => schema.user.find(request.params.id).institutions.all()); + this.get('/users/:id/registrations/', (schema, request) => schema.user.find(request.params.id).registrations.all()); + + this.get('/nodes/', (schema) => schema.node.all()); + this.get('/nodes/:id/', (schema, request) => schema.node.find(request.params.id)); + this.get('/nodes/:id/contributors/', (schema, request) => schema.node.find(request.params.id).contributors.all()); + this.get('/nodes/:id/logs/', (schema, request) => schema.node.find(request.params.id).logs.all()); + + this.get('/registrations/', (schema) => schema.registration.all()); + this.get('/registrations/:id/', (schema, request) => schema.registration.find(request.params.id)); + this.get('/registrations/:id/contributors/', (schema, request) => schema.registration.find(request.params.id).contributors.all()); + this.get('/registrations/:id/logs/', (schema, request) => schema.registration.find(request.params.id).logs.all()); + + this.get('/logs/', (schema) => schema.log.all()); + this.get('/logs/:id/', (schema, request) => schema.log.find(request.params.id)); + this.get('/logs/:id/contributors/', (schema, request) => schema.log.find(request.params.id).contributors.all()); + + this.get('/institutions/', (schema) => schema.institution.all()); + this.get('/institutions/:id/nodes/', (schema, request) => schema.institution.find(request.params.id).nodes.all()); + this.get('/institutions/:id/registrations/', (schema, request) => schema.institution.find(request.params.id).registrations.all()); + this.get('/institutions/:id/users/', (schema, request) => schema.institution.find(request.params.id).users.all()); + + /* + Shorthand cheatsheet: + this.get('/posts'); + this.post('/posts'); + this.get('/posts/:id'); + this.put('/posts/:id'); // or this.patch + this.del('/posts/:id'); + */ +} diff --git a/tests/dummy/mirage/factories/contributor.js b/tests/dummy/mirage/factories/contributor.js new file mode 100644 index 000000000..0ec1f5d9f --- /dev/null +++ b/tests/dummy/mirage/factories/contributor.js @@ -0,0 +1,17 @@ +import { + Factory, + faker +} from 'ember-cli-mirage'; + +import { + PERMISSIONS +} from 'ember-osf/const/permissions'; + +import { + pickOne +} from '../util'; + +export default Factory.extend({ + bibliographic: faker.random.boolean, + permission: pickOne(PERMISSIONS) +}); diff --git a/tests/dummy/mirage/factories/institution.js b/tests/dummy/mirage/factories/institution.js new file mode 100644 index 000000000..588c646b3 --- /dev/null +++ b/tests/dummy/mirage/factories/institution.js @@ -0,0 +1,5 @@ +import { + Factory +} from 'ember-cli-mirage'; + +export default Factory.extend({}); diff --git a/tests/dummy/mirage/factories/log.js b/tests/dummy/mirage/factories/log.js new file mode 100644 index 000000000..588c646b3 --- /dev/null +++ b/tests/dummy/mirage/factories/log.js @@ -0,0 +1,5 @@ +import { + Factory +} from 'ember-cli-mirage'; + +export default Factory.extend({}); diff --git a/tests/dummy/mirage/factories/node.js b/tests/dummy/mirage/factories/node.js new file mode 100644 index 000000000..00c7dea7f --- /dev/null +++ b/tests/dummy/mirage/factories/node.js @@ -0,0 +1,42 @@ +import { + Factory, + faker +} from 'ember-cli-mirage'; + +import NodeModel from 'ember-osf/models/node'; +var CATEGORIES = Object.keys(NodeModel.CATEGORY_MAP); + +import { + pickOne +} from '../util'; + +import { + PERMISSIONS +} from 'ember-osf/const/permissions'; + +export default Factory.extend({ + title: function() { + return `${faker.hacker.adjective()} ${faker.hacker.noun()} ${faker.hacker.verb()} ${faker.hacker.noun()}`; + }, + description: faker.hacker.phrase, + category: pickOne(CATEGORIES), + currentUserPermissions: pickOne(PERMISSIONS), + + fork: faker.random.boolean, + collection: faker.random.boolean, + registration: faker.random.boolean, + public: faker.random.boolean, + + dateCreated: faker.date.past, + dateModified: function() { + return faker.date.between(this.dateCreated, new Date()); + }, + + tags: function() { + return [ + faker.company.catchPhraseNoun(), + faker.company.catchPhraseNoun(), + faker.company.catchPhraseNoun() + ]; + } +}); diff --git a/tests/dummy/mirage/factories/registration.js b/tests/dummy/mirage/factories/registration.js new file mode 100644 index 000000000..2e878248c --- /dev/null +++ b/tests/dummy/mirage/factories/registration.js @@ -0,0 +1,45 @@ +import { + faker +} from 'ember-cli-mirage'; + +import NodeFactory from './node'; + +export default NodeFactory.extend({ + dateRegistered: faker.date.past, + embargoEndDate: faker.date.future, + + pendingRegistrationApproval: faker.random.boolean, + pendingEmbargoApproval: function() { + if (this.pendingRegistrationApproval) { + return false; + } + return faker.random.boolean(); + }, + + withdrawn: function() { + if (this.pendignRegistrationApproval || this.pendingEmbargoApproval) { + return false; + } + return faker.random.boolean(); + }, + withdrawalJustification: function() { + if (this.withdrawn) { + return faker.hacker.phrase(); + } + return null; + }, + pendingWithdrawal: function() { + if (!(this.pendignRegistrationApproval || this.pendingEmbargoApproval) && !this.withdrawn) { + return faker.random.boolean(); + } + return false; + }, + + registrationSupplement: function() { + return `${faker.hacker.adjective()} Preregistration (${faker.name.lastName} et al., ${faker.date.past().getFullYear()}`; + }, + registeredMeta: function() { + // TODO + return {}; + } +}); diff --git a/tests/dummy/mirage/factories/user.js b/tests/dummy/mirage/factories/user.js new file mode 100644 index 000000000..bb44c2dde --- /dev/null +++ b/tests/dummy/mirage/factories/user.js @@ -0,0 +1,14 @@ +import { + Factory, + faker +} from 'ember-cli-mirage'; + +export default Factory.extend({ + givenName: faker.name.firstName, + middleNames: faker.name.firstName, + familyName: faker.name.lastName, + fullName: function() { + return `${this.givenName} ${this.middleNames} ${this.familyName}`; + }, + dateRegistered: faker.date.past +}); diff --git a/tests/dummy/mirage/models/contributor.js b/tests/dummy/mirage/models/contributor.js new file mode 100644 index 000000000..483522030 --- /dev/null +++ b/tests/dummy/mirage/models/contributor.js @@ -0,0 +1,8 @@ +import { + Model, + belongsTo +} from 'ember-cli-mirage'; + +export default Model.extend({ + user: belongsTo('user') +}); diff --git a/tests/dummy/mirage/models/institutions.js b/tests/dummy/mirage/models/institutions.js new file mode 100644 index 000000000..ce7234d07 --- /dev/null +++ b/tests/dummy/mirage/models/institutions.js @@ -0,0 +1,16 @@ +import { + Model, + hasMany +} from 'ember-cli-mirage'; + +export default Model.extend({ + users: hasMany('users', { + inverseOf: 'affiliatedInstitutions' + }), + nodes: hasMany('nodes', { + inverseOf: 'affiliatedInstitutions' + }), + registrations: hasMany('registrations', { + inverseOf: 'affiliatedInstitutions' + }) +}); diff --git a/tests/dummy/mirage/models/logs.js b/tests/dummy/mirage/models/logs.js new file mode 100644 index 000000000..008e2d077 --- /dev/null +++ b/tests/dummy/mirage/models/logs.js @@ -0,0 +1,12 @@ +import { + Model, + belongsTo +} from 'ember-cli-mirage'; + +export default Model.extend({ + node: belongsTo('node'), + originalNode: belongsTo('node'), + user: belongsTo('user'), + linkedNode: belongsTo('node'), + templateNode: belongsTo('node') +}); diff --git a/tests/dummy/mirage/models/node.js b/tests/dummy/mirage/models/node.js new file mode 100644 index 000000000..0683fd884 --- /dev/null +++ b/tests/dummy/mirage/models/node.js @@ -0,0 +1,26 @@ +import { + Model, + belongsTo, + hasMany +} from 'ember-cli-mirage'; + +export default Model.extend({ + parent: belongsTo('node'), + children: hasMany('nodes', { + inverseOf: 'parent' + }), + affiliatedInstitutions: hasMany('institutions', { + inverseOf: 'nodes' + }), + contributors: hasMany('contributors'), + + // comments: hasMany('comments'), + //files: DS.hasMany('files'), + forkedFrom: belongsTo('node'), + //nodeLinks: DS.hasMany('node-pointers'), + registrations: hasMany('registrations', { + inverseOf: 'registeredFrom' + }), + + root: belongsTo('node') +}); diff --git a/tests/dummy/mirage/models/registration.js b/tests/dummy/mirage/models/registration.js new file mode 100644 index 000000000..14750c8c7 --- /dev/null +++ b/tests/dummy/mirage/models/registration.js @@ -0,0 +1,13 @@ +import { + belongsTo, + hasMany +} from 'ember-cli-mirage'; + +import NodeMirageModel from './node'; + +export default NodeMirageModel.extend({ + registeredFrom: belongsTo('node'), + registeredBy: belongsTo('user'), + contributors: hasMany('contributors') + // comments: hasMany('comments') +}); diff --git a/tests/dummy/mirage/models/user.js b/tests/dummy/mirage/models/user.js new file mode 100644 index 000000000..a23068b02 --- /dev/null +++ b/tests/dummy/mirage/models/user.js @@ -0,0 +1,12 @@ +import { + Model, + hasMany +} from 'ember-cli-mirage'; + +export default Model.extend({ + nodes: hasMany('nodes'), + registrations: hasMany('registrations'), + affiliatedInstitutions: hasMany('institutions', { + inverseOf: 'users' + }) +}); diff --git a/tests/dummy/mirage/scenarios/default.js b/tests/dummy/mirage/scenarios/default.js new file mode 100644 index 000000000..c5e299f13 --- /dev/null +++ b/tests/dummy/mirage/scenarios/default.js @@ -0,0 +1,11 @@ +export default function( /* server */ ) { + + /* + Seed your development database using your factories. + This data will not be loaded in your tests. + + Make sure to define a factory for each model you want to create. + */ + + // server.createList('post', 10); +} diff --git a/tests/dummy/mirage/serializers/application.js b/tests/dummy/mirage/serializers/application.js new file mode 100644 index 000000000..b4852fe6b --- /dev/null +++ b/tests/dummy/mirage/serializers/application.js @@ -0,0 +1,4 @@ +import JSONAPISerializer from 'ember-cli-mirage'; + +export default JSONAPISerializer.extend({ +}); diff --git a/tests/dummy/mirage/util.js b/tests/dummy/mirage/util.js new file mode 100644 index 000000000..5e3c321a9 --- /dev/null +++ b/tests/dummy/mirage/util.js @@ -0,0 +1,7 @@ +export default { + pickOne: function(list) { + return function() { + return list[Math.floor(Math.random() * list.length)]; + }; + } +}; From 10b3d1eb25e7fd097ac438634d67c211d182f784 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 13 May 2016 13:55:06 -0400 Subject: [PATCH 140/959] Style cleanup --- addon/serializers/osf-serializer.js | 8 ++++---- index.js | 12 ++++-------- package.json | 4 +++- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/addon/serializers/osf-serializer.js b/addon/serializers/osf-serializer.js index 8c6248c9f..4cdc7d1b0 100644 --- a/addon/serializers/osf-serializer.js +++ b/addon/serializers/osf-serializer.js @@ -37,12 +37,12 @@ export default DS.JSONAPISerializer.extend({ } delete resourceHash.embeds; //Recurse in, includeds are only processed on the top level. Emebeds are nested. - return included.concat(included.reduce((acc, include) => acc.concat(this._extractEmbeds(include)), [])); + return included.concat(included.reduce((acc, include) => acc.concat(this._extractEmbeds(include)), [])); }, _mergeFields(resourceHash) { // ApiV2 `links` exist outside the attributes field; make them accessible to the data model - if (resourceHash.links) { // TODO: Should also test whether model class defines a links field + if (resourceHash.links) { // TODO: Should also test whether model class defines a links field resourceHash.attributes.links = resourceHash.links; } @@ -50,8 +50,8 @@ export default DS.JSONAPISerializer.extend({ }, _normalizeDocumentHelper(documentHash) { - // Note: overrides a private method of the JSONAPISerializer. This is the best place to get the raw - // serialized document. + // Note: overrides a private method of the JSONAPISerializer. This is the best place to get the raw + // serialized document. documentHash.included = this._extractEmbeds(documentHash.data); return this._super(documentHash); }, diff --git a/index.js b/index.js index fbf695471..78cbe53d9 100644 --- a/index.js +++ b/index.js @@ -30,23 +30,19 @@ module.exports = { ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; ENV.OSF.isLocal = true; - } - else if (BACKEND === 'stage') { + } else if (BACKEND === 'stage') { ENV.OSF.url = 'https://staging.osf.io/'; ENV.OSF.apiUrl = 'https://staging-api.osf.io'; ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; - } - else if (BACKEND === 'stage2') { + } else if (BACKEND === 'stage2') { ENV.OSF.url = 'https://staging2.osf.io/'; ENV.OSF.apiUrl = 'https://staging2-api.osf.io'; ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; - } - else if (BACKEND === 'test') { + } else if (BACKEND === 'test') { ENV.OSF.url = 'https://test.osf.io/'; ENV.OSF.apiUrl = 'https://test-api.osf.io'; ENV.OSF.authUrl = 'https://test-accounts.osf.io/oauth2/authorize'; - } - else if (BACKEND === 'prod') { + } else if (BACKEND === 'prod') { console.log(`WARNING: you\'ve specified production as a backend. Please do not use production for testing or development purposes`); ENV.OSF.url = 'https://osf.io/'; ENV.OSF.apiUrl = 'https://api.osf.io'; diff --git a/package.json b/package.json index b48dd0cf1..f10a79c3d 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,8 @@ "requirePaddingNewLinesAfterBlocks": false, "validateIndentation": 4, "requirePaddingNewLinesBeforeLineComments": false, - "maximumLineLength": false + "maximumLineLength": false, + "disallowSpacesInsideParentheses": false, + "disallowNewlineBeforeBlockStatements": true } } From 512ba124c753f2a67dda8f1821f7fe245240c6e6 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 13 May 2016 14:00:19 -0400 Subject: [PATCH 141/959] Fix broken dependencies and package.json formatting --- bower.json | 7 ++++--- package.json | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/bower.json b/bower.json index 3bb49e852..0fc9ff92e 100644 --- a/bower.json +++ b/bower.json @@ -5,11 +5,12 @@ "ember-cli-shims": "0.1.1", "ember-cli-test-loader": "0.2.1", "ember-qunit-notifications": "0.1.0", - "Faker": "~3.0.0", - "pretender": "~0.12.0", "lodash": "~3.7.0" }, "devDependencies": { - "bootstrap": "^3.3.6" + "bootstrap": "^3.3.6", + "FakeXMLHttpRequest": "^1.3.0", + "Faker": "~3.0.0", + "pretender": "~0.12.0" } } diff --git a/package.json b/package.json index f10a79c3d..61a7ec6f9 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build": "ember build", "start": "ember server", "test": "ember test", - "check-style": "./node_modules/jscs/bin/jscs ." + "check-style": "./node_modules/jscs/bin/jscs ." }, "repository": "", "engines": { @@ -68,16 +68,16 @@ "jscsConfig": { "preset": "airbnb", "excludeFiles": [ - "bower_components", - "dist", - "tmp", - "vendor", - "app/locales", - "tests/unit", - "tests/integration", - "tests/helpers", - "tests/dummy/app/mirage" - ], + "bower_components", + "dist", + "tmp", + "vendor", + "app/locales", + "tests/unit", + "tests/integration", + "tests/helpers", + "tests/dummy/app/mirage" + ], "requireSpacesInAnonymousFunctionExpression": false, "requireTrailingComma": false, "disallowTrailingComma": false, @@ -85,7 +85,7 @@ "validateIndentation": 4, "requirePaddingNewLinesBeforeLineComments": false, "maximumLineLength": false, - "disallowSpacesInsideParentheses": false, - "disallowNewlineBeforeBlockStatements": true + "disallowSpacesInsideParentheses": false, + "disallowNewlineBeforeBlockStatements": true } } From e77b1a41b7d91b566fcb06f4c17bf2988b685f1d Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 13 May 2016 14:04:02 -0400 Subject: [PATCH 142/959] Get tests passing (still WIP) --- addon/models/file-provider.js | 2 +- addon/models/user.js | 2 +- tests/unit/serializers/osf-serializer-test.js | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index 102b5afca..f97ac4ff6 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -11,5 +11,5 @@ export default DS.Model.extend(OsfModel, { files: DS.hasMany('file'), node: DS.belongsTo('node'), - isFolder: Ember.computed.equal('kind', 'folder'), + isFolder: Ember.computed.equal('kind', 'folder') }); diff --git a/addon/models/user.js b/addon/models/user.js index 7477786a0..66dcea979 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -14,6 +14,6 @@ export default DS.Model.extend(OsfModel, { registrations: DS.hasMany('registrations'), affiliatedInstitutions: DS.hasMany('institutions', { - inverse: 'children' + inverse: 'users' }) }); diff --git a/tests/unit/serializers/osf-serializer-test.js b/tests/unit/serializers/osf-serializer-test.js index 283ee4313..6d4985d82 100644 --- a/tests/unit/serializers/osf-serializer-test.js +++ b/tests/unit/serializers/osf-serializer-test.js @@ -17,6 +17,7 @@ test('#_mergeFields adds links to attributes if included in payload', function(a let normalized = serializer._mergeFields(payload); assert.equal(normalized.attributes.links, payload.links); }); +/* TODO fixme test('#_mergeFields adds embeds to attributes if included in payload', function(assert) { let payload = { id: faker.random.uuid(), @@ -34,3 +35,4 @@ test('#_mergeFields adds embeds to attributes if included in payload', function( assert.equal(normalized.attributes.embeds, payload.embeds); }); +*/ From 23dd16bf0daf7e5af250c74faf64754a8353e5eb Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Fri, 13 May 2016 14:38:12 -0400 Subject: [PATCH 143/959] Add dependency required for components with templates [#EOSF-37] [ci skip] --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 8ee38ab2f..ae399a93c 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "ember-cli-moment-shim": "1.1.0", "ember-cli-node-assets": "^0.1.3", "ember-get-config": "0.0.2", + "ember-cli-htmlbars": "^1.0.1", "ember-moment": "6.1.0", "ember-simple-auth": "1.1.0-beta.5", "js-yaml": "^3.6.0" From 0c41e9c3658137f286b34d1afa2b3e5132531dba Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 13 May 2016 15:33:23 -0400 Subject: [PATCH 144/959] Implement file-service [skip ci] --- addon/models/file.js | 13 +++- addon/services/file-manager.js | 110 +++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 2 deletions(-) diff --git a/addon/models/file.js b/addon/models/file.js index 625d07f13..2c53ebe97 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -2,6 +2,16 @@ import Ember from 'ember'; import DS from 'ember-data'; import OsfModel from 'ember-osf/models/base'; +/* +function readonlyAttr(transform) { + return DS.attr(transform).extend({ + set() { + // just throw? + } + }); +} +*/ + export default OsfModel.extend({ name: DS.attr('string'), kind: DS.attr('string'), @@ -23,8 +33,7 @@ export default OsfModel.extend({ // File attributes versions: DS.hasMany('file-version'), comments: DS.hasMany('comment'), - //contents: DS.belongsTo('file-contents'), - parentFolder: DS.belongsTo('file'), + parentFolder: DS.belongsTo('file', { inverse: 'files' }), isFolder: Ember.computed.equal('kind', 'folder'), }); diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index b9261c61d..8d6589974 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -1,4 +1,114 @@ import Ember from 'ember'; export default Ember.Service.extend({ + session: Ember.inject.service('session'), + + // File actions + getContents(file) { + var url = file.get('links').download; + return this._waterbutlerRequest('GET', url); + }, + + updateContents(file, contents) { + var url = file.get('links').upload; + return this._waterbutlerRequest('PUT', url, { + kind: 'file' + }, contents); + }, + + checkout(file, user) { + // TODO? Having checkout here makes more sense to me than making it + // the only writable attribute on the file model. + }, + + // Folder actions + addSubfolder(folder, name) { + var url = folder.get('links').new_folder; + + // HACK: This is the only link that already has a query string + if (url.search(/\?kind=folder$/) > -1) { + url = `${url}&name=${name}`; + return this._waterbutlerRequest('PUT', url); + } else { + return this._waterbutlerRequest('PUT', url, { + name, + kind: 'folder' + }); + } + }, + + uploadFile(folder, name, contents) { + var url = folder.get('links').upload; + return this._waterbutlerRequest('PUT', url, { + name, + kind: 'file' + }, contents); + }, + + // File and folder actions + rename(file, newName) { + var url = file.get('links').move; + return this._waterbutlerRequest('POST', url, data = { + action: 'rename', + rename: newName + }); + }, + + move(file, targetFolder, newName=null, replace=true, node=null, + provider=null, action='move') { + var url = file.get('links').move; + var data = { + action, + path: targetFolder.get('path'), + conflict: replace ? 'replace' : 'keep' + }; + if (newName) { + data.rename = newName; + } + if (node) { + if (typeof node === 'string') { + data.resource = node; + } else { + data.resource = node.get('id'); + } + } + if (provider) { + data.provider = provider; + } + return this._waterbutlerRequest('POST', url, data=data); + }, + + copy(file, targetFolder, newName=null, + replace=true, node=null, provider=null) { + return this.move(file, targetFolder, newName, replace, + node, provider, 'copy'); + }, + + deleteFile(file) { + var url = folder.get('links').delete; + return this._waterbutlerRequest('DELETE', url); + }, + + _waterbutlerRequest(method, url, queryParams=null, data=null) { + if (queryParams) { + let queryString = Ember.$.param(queryParams); + url = `${url}?${queryString}`; + } + var sessionData = this.get('session').get('data'); + var accessToken = sessionData.authenticated.attributes.accessToken; + return new Ember.RSVP.Promise(function(resolve, reject) { + Ember.$.ajax(url, { + method, + headers: { + Authorization: `Bearer ${accessToken}` + }, + error(_, __, errorMsg) { + reject(new Error(errorMsg)); + }, + success(data) { + resolve(data); + } + }); + }); + } }); From c5c530fd470bec5a2e3399a2a989d8e44be61662 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 13 May 2016 15:36:04 -0400 Subject: [PATCH 145/959] Remove file-contents model [skip ci] --- addon/models/file-contents.js | 7 ------- app/models/file-contents.js | 1 - tests/unit/models/file-contents-test.js | 12 ------------ 3 files changed, 20 deletions(-) delete mode 100644 addon/models/file-contents.js delete mode 100644 app/models/file-contents.js delete mode 100644 tests/unit/models/file-contents-test.js diff --git a/addon/models/file-contents.js b/addon/models/file-contents.js deleted file mode 100644 index d3d7a8056..000000000 --- a/addon/models/file-contents.js +++ /dev/null @@ -1,7 +0,0 @@ -//import DS from 'ember-data'; - -import OsfModel from 'ember-osf/models/base'; - -export default OsfModel.extend({ - // TODO fetch file content from waterbutler -}); diff --git a/app/models/file-contents.js b/app/models/file-contents.js deleted file mode 100644 index a9bf42148..000000000 --- a/app/models/file-contents.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/models/file-contents'; diff --git a/tests/unit/models/file-contents-test.js b/tests/unit/models/file-contents-test.js deleted file mode 100644 index 732f1ac43..000000000 --- a/tests/unit/models/file-contents-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('file-contents', 'Unit | Model | file contents', { - // Specify the other units that are required for this test. - needs: [] -}); - -test('it exists', function(assert) { - let model = this.subject(); - // let store = this.store(); - assert.ok(!!model); -}); From dedbe3c4ad93cd4bb5ef29fee1a6ab0e7d1ed7a7 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 13 May 2016 17:05:37 -0400 Subject: [PATCH 146/959] Add nested children route. --- tests/dummy/app/router.js | 2 ++ tests/dummy/app/routes/nodes/detail/children.js | 7 +++++++ tests/dummy/app/templates/nodes/detail.hbs | 1 + tests/dummy/app/templates/nodes/detail/children.hbs | 5 +++++ 4 files changed, 15 insertions(+) create mode 100644 tests/dummy/app/routes/nodes/detail/children.js create mode 100644 tests/dummy/app/templates/nodes/detail/children.hbs diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 216e91a03..cb58780eb 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -12,6 +12,8 @@ Router.map(function() { this.route('nodes', function() { this.route('detail', { path: '/:node_id' + }, function() { + this.route('children'); }); }); this.route('login'); diff --git a/tests/dummy/app/routes/nodes/detail/children.js b/tests/dummy/app/routes/nodes/detail/children.js new file mode 100644 index 000000000..c28d6678b --- /dev/null +++ b/tests/dummy/app/routes/nodes/detail/children.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model(params) { + return this.store.query('node', { filter: { parent: this.modelFor('nodes.detail').get('id')}}); + } +}); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index ad892f006..96ee12e81 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -83,3 +83,4 @@ {{log-detail node-logs=model.logs}} +{{outlet}} diff --git a/tests/dummy/app/templates/nodes/detail/children.hbs b/tests/dummy/app/templates/nodes/detail/children.hbs new file mode 100644 index 000000000..b13eb3c98 --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/children.hbs @@ -0,0 +1,5 @@ +
+

Children

+{{#each model as |child|}} + {{child.title}} +{{/each}} From 9164b7a72946cd4edeb533d6484d7aee3bca5590 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 13 May 2016 17:06:13 -0400 Subject: [PATCH 147/959] Javascript errors. --- tests/dummy/app/router.js | 2 +- tests/dummy/app/routes/nodes/detail/children.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index cb58780eb..55212e693 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -13,7 +13,7 @@ Router.map(function() { this.route('detail', { path: '/:node_id' }, function() { - this.route('children'); + this.route('children'); }); }); this.route('login'); diff --git a/tests/dummy/app/routes/nodes/detail/children.js b/tests/dummy/app/routes/nodes/detail/children.js index c28d6678b..e7aff7e27 100644 --- a/tests/dummy/app/routes/nodes/detail/children.js +++ b/tests/dummy/app/routes/nodes/detail/children.js @@ -1,7 +1,11 @@ import Ember from 'ember'; export default Ember.Route.extend({ - model(params) { - return this.store.query('node', { filter: { parent: this.modelFor('nodes.detail').get('id')}}); + model() { + return this.store.query('node', { + filter: { + parent: this.modelFor('nodes.detail').get('id') + } + }); } }); From d2514443772df96a516eb86a1ed70bc99ce0671f Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 16 May 2016 11:10:33 -0400 Subject: [PATCH 148/959] No need for separate serialize/deserialize checks Fix issue with profile pages --- addon/serializers/osf-serializer.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/addon/serializers/osf-serializer.js b/addon/serializers/osf-serializer.js index 6d5eba9a2..5286ff91a 100644 --- a/addon/serializers/osf-serializer.js +++ b/addon/serializers/osf-serializer.js @@ -30,12 +30,8 @@ export default DS.JSONAPISerializer.extend({ return this._super(modelClass, resourceHash); }, - keyForAttribute(key, method) { - if (method === 'deserialize') { - return Ember.String.underscore(key); - } else if (method === 'serialize') { - return Ember.String.camelize(key); - } + keyForAttribute(key) { + return Ember.String.underscore(key); }, keyForRelationship(key) { return Ember.String.underscore(key); From 4e22b1ee136521037de9ed4e571a75d9d7561c7b Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 12:04:29 -0400 Subject: [PATCH 149/959] Add ability to change node from public to private. --- tests/dummy/app/routes/nodes/detail.js | 3 ++- tests/dummy/app/templates/nodes/detail.hbs | 17 +++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index f84c15469..0034a1815 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -13,7 +13,7 @@ export default Ember.Route.extend({ }, actions: { - editExisting(title, description, category) { + editExisting(title, description, category, isPublic) { // TODO: Should test PUT or PATCH // console.log('Will edit title from', this.modelFor(this.routeName).get('title'), ' to ', value); var node = this.modelFor(this.routeName); @@ -22,6 +22,7 @@ export default Ember.Route.extend({ if (title) {node.set('title', title);} if (category) {node.set('category', category);} if (description) {node.set('description', description);} + if (isPublic) {node.set('public', isPublic);} node.save(); } else { console.log('You do not have permissions to edit this node'); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 96ee12e81..1fad81cdd 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -7,6 +7,7 @@

{{model.category}}

{{moment-format model.dateCreated}}

{{moment-format model.dateModified}}

+

{{model.public}}

View on OSF @@ -18,17 +19,17 @@

- - + + - - + +
Title: {{input value=editedTitle}} {{input value=editedTitle}}
Description: {{input value=editedDescription}} {{input value=editedDescription}}
-

Category:

+

{{radio-button name="category" value="analysis" checked=editedCategory}} Analysis
{{radio-button name="category" value="communication" checked=editedCategory}} Communication
@@ -44,7 +45,11 @@

- +

+ {{radio-button name="isPublic" value=1 checked=isPublic}} Public
+ {{radio-button name="isPublic" value=0 checked=isPublic}} Private
+ + {{else}} From 7db00f30f1b62d288318a405ac9cd2e8efc550ce Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 12:05:08 -0400 Subject: [PATCH 150/959] Add children model with parentId attribute. --- addon/models/children.js | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 addon/models/children.js diff --git a/addon/models/children.js b/addon/models/children.js new file mode 100644 index 000000000..c81dd0a3c --- /dev/null +++ b/addon/models/children.js @@ -0,0 +1,48 @@ +import DS from 'ember-data'; + +import OsfModel from '../mixins/osf-model'; + +export default DS.Model.extend(OsfModel, { + title: DS.attr('string'), + description: DS.attr('string'), + category: DS.attr('string'), + parentId: DS.attr('string'), + + currentUserPermissions: DS.attr('string'), + + fork: DS.attr('boolean'), + collection: DS.attr('boolean'), + registration: DS.attr('boolean'), + public: DS.attr('boolean'), + + dateCreated: DS.attr('date'), + dateModified: DS.attr('date'), + + tags: DS.attr(), + + templateFrom: DS.attr('string'), + + parent: DS.belongsTo('node', { + inverse: 'children' + }), + children: DS.hasMany('nodes', { + inverse: 'parent' + }), + affiliatedInstitutions: DS.hasMany('institutions', { + inverse: 'nodes' + }), + comments: DS.hasMany('comments'), + contributors: DS.hasMany('contributors'), + + files: DS.hasMany('file-provider'), + //forkedFrom: DS.belongsTo('node'), + //nodeLinks: DS.hasMany('node-pointers'), + registrations: DS.hasMany('registrations', { + inverse: 'registeredFrom' + }), + + root: DS.belongsTo('node', { + inverse: null + }), + logs: DS.hasMany('logs') +}); From e6687d3d0d22c11441ea9974fa126aeae1a156fa Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 12:06:53 -0400 Subject: [PATCH 151/959] Add children adapter that modifies base url to use /nodes/node_id/children instead of nodes/children. --- addon/adapters/children.js | 11 +++++++++++ app/adapters/children.js | 1 + app/models/children.js | 1 + tests/unit/adapters/children-test.js | 12 ++++++++++++ tests/unit/models/children-test.js | 12 ++++++++++++ 5 files changed, 37 insertions(+) create mode 100644 addon/adapters/children.js create mode 100644 app/adapters/children.js create mode 100644 app/models/children.js create mode 100644 tests/unit/adapters/children-test.js create mode 100644 tests/unit/models/children-test.js diff --git a/addon/adapters/children.js b/addon/adapters/children.js new file mode 100644 index 000000000..9bdea0b36 --- /dev/null +++ b/addon/adapters/children.js @@ -0,0 +1,11 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ + buildURL(_, __, snap, requestType) { + // Embed contributors + var base = this._super(...arguments); + var ar = base.split('/'); + ar.splice(4, 0, 'nodes/' + snap._attributes.parentId); + return ar.join('/'); + } +}); diff --git a/app/adapters/children.js b/app/adapters/children.js new file mode 100644 index 000000000..cad40a625 --- /dev/null +++ b/app/adapters/children.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/children'; diff --git a/app/models/children.js b/app/models/children.js new file mode 100644 index 000000000..0bc501b82 --- /dev/null +++ b/app/models/children.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/children'; diff --git a/tests/unit/adapters/children-test.js b/tests/unit/adapters/children-test.js new file mode 100644 index 000000000..720d9943e --- /dev/null +++ b/tests/unit/adapters/children-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:children', 'Unit | Adapter | children', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/models/children-test.js b/tests/unit/models/children-test.js new file mode 100644 index 000000000..2e28dbab8 --- /dev/null +++ b/tests/unit/models/children-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('children', 'Unit | Model | children', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); From 789afe717343833e404ec56a77dcb6acb7827e5e Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 12:07:44 -0400 Subject: [PATCH 152/959] Add children serializer that changes type from 'children' to 'nodes' and removes relationships from payload. APIv2 does not support "children" type. --- addon/serializers/children.js | 12 ++++++++++++ app/serializers/children.js | 1 + tests/unit/serializers/children-test.js | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 addon/serializers/children.js create mode 100644 app/serializers/children.js create mode 100644 tests/unit/serializers/children-test.js diff --git a/addon/serializers/children.js b/addon/serializers/children.js new file mode 100644 index 000000000..2e8f0a8bb --- /dev/null +++ b/addon/serializers/children.js @@ -0,0 +1,12 @@ +import OsfSerializer from './osf-serializer'; + +export default OsfSerializer.extend({ + serialize: function(snapshot, options) { + var serialized = this._super(snapshot, options); + // Don't send relationships to the server; this can lead to 500 errors. + delete serialized.data.relationships; + // Change type from 'children' to 'nodes'. APIv2 does not have children type. + serialized.data.type = 'nodes'; + return serialized; + } +}); diff --git a/app/serializers/children.js b/app/serializers/children.js new file mode 100644 index 000000000..3ca5bec68 --- /dev/null +++ b/app/serializers/children.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/children'; diff --git a/tests/unit/serializers/children-test.js b/tests/unit/serializers/children-test.js new file mode 100644 index 000000000..7edf77a4e --- /dev/null +++ b/tests/unit/serializers/children-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('children', 'Unit | Serializer | children', { + // Specify the other units that are required for this test. + needs: ['serializer:children'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); From a9698f92df50262f7164b9a35314932b4920e787 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 12:08:21 -0400 Subject: [PATCH 153/959] Add addChildren action to nodes detail route. --- tests/dummy/app/routes/nodes/detail.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 0034a1815..175ccf09d 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -27,7 +27,18 @@ export default Ember.Route.extend({ } else { console.log('You do not have permissions to edit this node'); } + }, + addChildren(title, description, category) { + var node = this.modelFor(this.routeName); + var child = this.store.createRecord('children', { + title: title, + category: category || 'project', + description: description || null, + parentId: node.id + }); + child.save(); } + } }); From 8cfd0ebcf89f7e4f6fa74f0ab4d45c956fde5a4e Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 12:08:46 -0400 Subject: [PATCH 154/959] Add create component view to nodes detail template. --- tests/dummy/app/templates/nodes/detail.hbs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 1fad81cdd..9fbda8fee 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -88,4 +88,28 @@ {{log-detail node-logs=model.logs}}
+ +

Create component

+
+ + {{input type="text" value=title placeholder="Component's title" required=true}}
+ + {{input type="text" value=description placeholder="Component's description"}}
+
+ {{radio-button name="category" value="analysis" checked=category}} Analysis
+ {{radio-button name="category" value="communication" checked=category}} Communication
+ {{radio-button name="category" value="data" checked=category}} Data
+ {{radio-button name="category" value="hypothesis" checked=category}} Hypothesis
+ {{radio-button name="category" value="instrumentation" checked=category}} Instrumentation
+ {{radio-button name="category" value="methods and measures" checked=category}} Methods and Measures
+ {{radio-button name="category" value="procedure" checked=category}} Procedure
+ {{radio-button name="category" value="project" checked=category}} Project
+ {{radio-button name="category" value="software" checked=category}} Software
+ {{radio-button name="category" value="other" checked=category}} Other
+ {{radio-button name="category" value="uncategorized" checked=category}} Uncategorized
+
+

+ +
+ {{outlet}} From 1513be78c8c5c6c0ce62d2656529318a62df465f Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 12:09:02 -0400 Subject: [PATCH 155/959] Display children as a list. --- tests/dummy/app/templates/nodes/detail/children.hbs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail/children.hbs b/tests/dummy/app/templates/nodes/detail/children.hbs index b13eb3c98..fde294b04 100644 --- a/tests/dummy/app/templates/nodes/detail/children.hbs +++ b/tests/dummy/app/templates/nodes/detail/children.hbs @@ -1,5 +1,7 @@
-

Children

-{{#each model as |child|}} -
{{child.title}} -{{/each}} +

Components

+ From 028517c7ad7ae759166bcb33ad7f59053383fb36 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Mon, 16 May 2016 11:25:53 -0400 Subject: [PATCH 156/959] Add profile view/update route --- tests/dummy/app/router.js | 1 + tests/dummy/app/routes/profile.js | 24 ++++++++++++++++++++++++ tests/dummy/app/templates/index.hbs | 1 + tests/dummy/app/templates/profile.hbs | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 tests/dummy/app/routes/profile.js create mode 100644 tests/dummy/app/templates/profile.hbs diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 216e91a03..741aabfe3 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -33,6 +33,7 @@ Router.map(function() { this.route('file', { path: '/file/:file_id' }); + this.route('profile'); }); export default Router; diff --git a/tests/dummy/app/routes/profile.js b/tests/dummy/app/routes/profile.js new file mode 100644 index 000000000..886dcedec --- /dev/null +++ b/tests/dummy/app/routes/profile.js @@ -0,0 +1,24 @@ +import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default Ember.Route.extend(AuthenticatedRouteMixin, { + store: Ember.inject.service(), + session: Ember.inject.service(), + model() { + return this.get('store').findRecord('user', 'me'); + }, + + setupController(controller, model) { + controller.set('editedFullName', model.get('fullName')); + this._super(...arguments); + }, + + actions: { + editExisting(value) { + // TODO: Should test PUT or PATCH + var user = this.modelFor(this.routeName); + user.set('fullName', value); + user.save(); + } + } +}); diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs index 28d2bf17e..07919019b 100644 --- a/tests/dummy/app/templates/index.hbs +++ b/tests/dummy/app/templates/index.hbs @@ -2,3 +2,4 @@ {{link-to 'My Registrations' 'registrations' class="btn btn-warning"}} {{link-to 'All Institutions' 'institutions' class="btn btn-danger"}} {{link-to 'Users' 'users' class="btn btn-default"}} +{{link-to 'My Profile' 'profile' class="btn btn-default"}} diff --git a/tests/dummy/app/templates/profile.hbs b/tests/dummy/app/templates/profile.hbs new file mode 100644 index 000000000..5e18744eb --- /dev/null +++ b/tests/dummy/app/templates/profile.hbs @@ -0,0 +1,18 @@ +

Profile Information

+
+

{{model.fullName}}

+

{{model.givenName}}

+

{{model.middleName}}

+

{{model.familyName}}

+ +

+ + View on OSF + +

+
+ +

Edit your profile

+ Full Name: {{input value=editedFullName}} + +
From 96dd58d75afefc59510cda3e8cc81e82582d9043 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 13:00:26 -0400 Subject: [PATCH 157/959] Add ability to delete nodes. --- tests/dummy/app/routes/nodes/detail.js | 11 +++++++++++ tests/dummy/app/templates/nodes/detail.hbs | 3 +++ tests/unit/models/children-test.js | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 175ccf09d..9130309da 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -37,6 +37,17 @@ export default Ember.Route.extend({ parentId: node.id }); child.save(); + }, + deleteNode() { + var node = this.modelFor(this.routeName); + if (node.get('currentUserPermissions').indexOf('write') !== -1) { + node.one('didDelete', this, function () { + this.transitionTo('nodes.index'); + }); + node.destroyRecord(); + } else { + console.log('You do not have permissions to delete this node'); + } } } diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 9fbda8fee..3062492e1 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -13,6 +13,9 @@ View on OSF

+ +

+
{{#if propertiesVisible}} diff --git a/tests/unit/models/children-test.js b/tests/unit/models/children-test.js index 2e28dbab8..7032b3cc2 100644 --- a/tests/unit/models/children-test.js +++ b/tests/unit/models/children-test.js @@ -2,7 +2,8 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('children', 'Unit | Model | children', { // Specify the other units that are required for this test. - needs: [] + needs: ['model:user', 'model:contributor', 'model:comment', 'model:institution', 'model:registration', 'model:file-provider', 'model:log'] + }); test('it exists', function(assert) { From 2bccee5ac040f6249ceaac28b40315b9fac292f4 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Mon, 16 May 2016 13:01:39 -0400 Subject: [PATCH 158/959] Fix osf serializer --- addon/serializers/osf-serializer.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/addon/serializers/osf-serializer.js b/addon/serializers/osf-serializer.js index 6d5eba9a2..459a66292 100644 --- a/addon/serializers/osf-serializer.js +++ b/addon/serializers/osf-serializer.js @@ -30,13 +30,10 @@ export default DS.JSONAPISerializer.extend({ return this._super(modelClass, resourceHash); }, - keyForAttribute(key, method) { - if (method === 'deserialize') { - return Ember.String.underscore(key); - } else if (method === 'serialize') { - return Ember.String.camelize(key); - } + keyForAttribute(key) { + return Ember.String.underscore(key); }, + keyForRelationship(key) { return Ember.String.underscore(key); }, From 2402466afd86e0d09b0c5bc40a08910b29de7307 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 13:13:19 -0400 Subject: [PATCH 159/959] Transition to nodes/detail/children/ after creating a component. --- addon/serializers/children.js | 2 -- tests/dummy/app/routes/nodes/detail.js | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/addon/serializers/children.js b/addon/serializers/children.js index 2e8f0a8bb..e9434430b 100644 --- a/addon/serializers/children.js +++ b/addon/serializers/children.js @@ -3,8 +3,6 @@ import OsfSerializer from './osf-serializer'; export default OsfSerializer.extend({ serialize: function(snapshot, options) { var serialized = this._super(snapshot, options); - // Don't send relationships to the server; this can lead to 500 errors. - delete serialized.data.relationships; // Change type from 'children' to 'nodes'. APIv2 does not have children type. serialized.data.type = 'nodes'; return serialized; diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 9130309da..9ac10570a 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -30,13 +30,20 @@ export default Ember.Route.extend({ }, addChildren(title, description, category) { var node = this.modelFor(this.routeName); - var child = this.store.createRecord('children', { - title: title, - category: category || 'project', - description: description || null, - parentId: node.id - }); - child.save(); + if (node.get('currentUserPermissions').indexOf('write') !== -1) { + var child = this.store.createRecord('children', { + title: title, + category: category || 'project', + description: description || null, + parentId: node.id + }); + child.one('didCreate', this, function() { + this.transitionTo('nodes.detail.children'); + }); + child.save(); + } else { + console.log('You do not have permissions to create this component'); + } }, deleteNode() { var node = this.modelFor(this.routeName); From 0fffb510891f9ef087e8acb317d3a4a9cf873745 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 13:15:15 -0400 Subject: [PATCH 160/959] Adds more descriptive comment for children adapter. --- addon/adapters/children.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/adapters/children.js b/addon/adapters/children.js index 9bdea0b36..f9464e7b4 100644 --- a/addon/adapters/children.js +++ b/addon/adapters/children.js @@ -2,7 +2,7 @@ import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ buildURL(_, __, snap, requestType) { - // Embed contributors + // Modifies URL from /children/ to nodes//children/ to match APIv2 route for creating children. var base = this._super(...arguments); var ar = base.split('/'); ar.splice(4, 0, 'nodes/' + snap._attributes.parentId); From b48bfc2e723344d76f5eb30c451a8155e0f7c2c7 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 16 May 2016 13:23:54 -0400 Subject: [PATCH 161/959] Conceptual fix for errors when saving node.template_from to the server Not thoroughly tested; use at your own risk --- addon/serializers/osf-serializer.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addon/serializers/osf-serializer.js b/addon/serializers/osf-serializer.js index 5286ff91a..14367e92e 100644 --- a/addon/serializers/osf-serializer.js +++ b/addon/serializers/osf-serializer.js @@ -42,5 +42,16 @@ export default DS.JSONAPISerializer.extend({ // Don't send relationships to the server; this can lead to 500 errors. delete serialized.data.relationships; return serialized; + }, + + serializeAttribute(snapshot, json, key, attribute) { + // In certain cases, a field may be omitted from the server payload, but have a value (undefined) + // when serialized from the model. (eg node.template_from) + // Omit fields with a value of undefined before sending to the server. (but still allow null to be sent) + let val = snapshot.attr(key); + if (val !== undefined) { + this._super(...arguments); + } } + }); From 3051b8b7dfe12e4ce558cafb4877abbf005d57d4 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 16 May 2016 13:25:55 -0400 Subject: [PATCH 162/959] Fix jshint error --- addon/serializers/osf-serializer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/serializers/osf-serializer.js b/addon/serializers/osf-serializer.js index b734c77f7..1616a1e86 100644 --- a/addon/serializers/osf-serializer.js +++ b/addon/serializers/osf-serializer.js @@ -45,7 +45,7 @@ export default DS.JSONAPISerializer.extend({ return serialized; }, - serializeAttribute(snapshot, json, key, attribute) { + serializeAttribute(snapshot, json, key, attribute) { // jshint ignore:line // In certain cases, a field may be omitted from the server payload, but have a value (undefined) // when serialized from the model. (eg node.template_from) // Omit fields with a value of undefined before sending to the server. (but still allow null to be sent) From 54d9ef55ddc5425a940c7ee0543b1f00e40dd979 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 13:41:30 -0400 Subject: [PATCH 163/959] Fix failing tests. --- addon/adapters/children.js | 2 +- tests/unit/adapters/children-test.js | 2 +- tests/unit/models/children-test.js | 2 +- tests/unit/serializers/children-test.js | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/addon/adapters/children.js b/addon/adapters/children.js index f9464e7b4..14e16d9d6 100644 --- a/addon/adapters/children.js +++ b/addon/adapters/children.js @@ -1,7 +1,7 @@ import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ - buildURL(_, __, snap, requestType) { + buildURL(_, __, snap) { // Modifies URL from /children/ to nodes//children/ to match APIv2 route for creating children. var base = this._super(...arguments); var ar = base.split('/'); diff --git a/tests/unit/adapters/children-test.js b/tests/unit/adapters/children-test.js index 720d9943e..45373afbb 100644 --- a/tests/unit/adapters/children-test.js +++ b/tests/unit/adapters/children-test.js @@ -2,7 +2,7 @@ import { moduleFor, test } from 'ember-qunit'; moduleFor('adapter:children', 'Unit | Adapter | children', { // Specify the other units that are required for this test. - // needs: ['serializer:foo'] + needs: ['model:node'] }); // Replace this with your real tests. diff --git a/tests/unit/models/children-test.js b/tests/unit/models/children-test.js index 7032b3cc2..f14e1e539 100644 --- a/tests/unit/models/children-test.js +++ b/tests/unit/models/children-test.js @@ -2,7 +2,7 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('children', 'Unit | Model | children', { // Specify the other units that are required for this test. - needs: ['model:user', 'model:contributor', 'model:comment', 'model:institution', 'model:registration', 'model:file-provider', 'model:log'] + needs: ['model:node', 'model:user', 'model:contributor', 'model:comment', 'model:institution', 'model:registration', 'model:file-provider', 'model:log'] }); diff --git a/tests/unit/serializers/children-test.js b/tests/unit/serializers/children-test.js index 7edf77a4e..2dae4f2d6 100644 --- a/tests/unit/serializers/children-test.js +++ b/tests/unit/serializers/children-test.js @@ -2,7 +2,8 @@ import { moduleForModel, test } from 'ember-qunit'; moduleForModel('children', 'Unit | Serializer | children', { // Specify the other units that are required for this test. - needs: ['serializer:children'] + needs: ['serializer:children', 'model:children', 'model:node', 'transform:links', 'transform:embed', 'model:institution', + 'model:contributor', 'model:comment', 'model:file-provider', 'model:registration', 'model:log'] }); // Replace this with your real tests. From 600b7db54b0ab29b8485324bdf6da0f6ad57da19 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 16 May 2016 14:08:43 -0400 Subject: [PATCH 164/959] Sample login page [#EOSF-37] [ci skip] --- addon/components/login-form.js | 14 ++++++++++++++ addon/templates/components/login-form.hbs | 11 +++++++++++ app/components/login-form.js | 1 + tests/dummy/app/controllers/cookielogin.js | 10 ++++++++++ tests/dummy/app/router.js | 1 + tests/dummy/app/routes/cookielogin.js | 13 +++++++++++++ tests/dummy/app/templates/cookielogin.hbs | 1 + 7 files changed, 51 insertions(+) create mode 100644 addon/components/login-form.js create mode 100644 addon/templates/components/login-form.hbs create mode 100644 app/components/login-form.js create mode 100644 tests/dummy/app/controllers/cookielogin.js create mode 100644 tests/dummy/app/routes/cookielogin.js create mode 100644 tests/dummy/app/templates/cookielogin.hbs diff --git a/addon/components/login-form.js b/addon/components/login-form.js new file mode 100644 index 000000000..612f728fb --- /dev/null +++ b/addon/components/login-form.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; +import layout from '../templates/components/login-form'; + + +// TODO: Future reading- add responsiveness on delays http://blog.trackets.com/2013/05/23/how-to-write-a-login-form.html +export default Ember.Component.extend({ + layout, + + actions: { + loginSubmit() { + this.sendAction('loginSubmit', ...arguments); + } + } +}); diff --git a/addon/templates/components/login-form.hbs b/addon/templates/components/login-form.hbs new file mode 100644 index 000000000..b6975b2b8 --- /dev/null +++ b/addon/templates/components/login-form.hbs @@ -0,0 +1,11 @@ +{{!-- app/templates/login.hbs --}} +
+ + {{input id='identification' placeholder='Enter Login' value=identification}} + + {{input id='password' placeholder='Enter Password' type='password' value=password}} + + {{#if errorMessage}} +

{{errorMessage}}

+ {{/if}} +
\ No newline at end of file diff --git a/app/components/login-form.js b/app/components/login-form.js new file mode 100644 index 000000000..0025d1cf1 --- /dev/null +++ b/app/components/login-form.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/login-form'; \ No newline at end of file diff --git a/tests/dummy/app/controllers/cookielogin.js b/tests/dummy/app/controllers/cookielogin.js new file mode 100644 index 000000000..517cacbe6 --- /dev/null +++ b/tests/dummy/app/controllers/cookielogin.js @@ -0,0 +1,10 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + actions: { + loginHandler: function () { + console.log('Called submit', ...arguments); + return true; + } + } +}); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 216e91a03..39322279a 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -33,6 +33,7 @@ Router.map(function() { this.route('file', { path: '/file/:file_id' }); + this.route('cookielogin'); }); export default Router; diff --git a/tests/dummy/app/routes/cookielogin.js b/tests/dummy/app/routes/cookielogin.js new file mode 100644 index 000000000..2251e8c10 --- /dev/null +++ b/tests/dummy/app/routes/cookielogin.js @@ -0,0 +1,13 @@ +import Ember from 'ember'; + +import OsfCookieLoginRoute from 'ember-osf/mixins/osf-cookie-login-route'; + + +export default Ember.Route.extend(OsfCookieLoginRoute , { + + // actions: { + // loginHandler: function(){ + // return true; + // } + // } +}); diff --git a/tests/dummy/app/templates/cookielogin.hbs b/tests/dummy/app/templates/cookielogin.hbs new file mode 100644 index 000000000..820ec351e --- /dev/null +++ b/tests/dummy/app/templates/cookielogin.hbs @@ -0,0 +1 @@ +{{login-form loginSubmit=(action 'loginHandler')}} From 73f7573adcb1862d551a50bd9f0b3cbeb8dec9fc Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 14:49:32 -0400 Subject: [PATCH 165/959] Override payloadKeyFromModelName hook instead of serialize hook on children serializer. --- addon/serializers/children.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/addon/serializers/children.js b/addon/serializers/children.js index e9434430b..b0345b08e 100644 --- a/addon/serializers/children.js +++ b/addon/serializers/children.js @@ -1,10 +1,8 @@ import OsfSerializer from './osf-serializer'; export default OsfSerializer.extend({ - serialize: function(snapshot, options) { - var serialized = this._super(snapshot, options); - // Change type from 'children' to 'nodes'. APIv2 does not have children type. - serialized.data.type = 'nodes'; - return serialized; + payloadKeyFromModelName: function() { + // Overrides type 'children' with type 'nodes'. APIv2 expecting type 'nodes'. + return 'nodes'; } }); From 6289b99b52978b6b2ba8c9a28e09a6ea428f422d Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 16 May 2016 14:49:56 -0400 Subject: [PATCH 166/959] Add cookie login mixins for route --- addon/mixins/osf-cookie-login-controller.js | 19 +++++++++++++++ tests/dummy/app/controllers/cookielogin.js | 10 +++----- tests/dummy/app/routes/cookielogin.js | 10 +------- .../integration/components/login-form-test.js | 24 +++++++++++++++++++ .../osf-cookie-login-controller-test.js | 12 ++++++++++ 5 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 addon/mixins/osf-cookie-login-controller.js create mode 100644 tests/integration/components/login-form-test.js create mode 100644 tests/unit/mixins/osf-cookie-login-controller-test.js diff --git a/addon/mixins/osf-cookie-login-controller.js b/addon/mixins/osf-cookie-login-controller.js new file mode 100644 index 000000000..e89eec99e --- /dev/null +++ b/addon/mixins/osf-cookie-login-controller.js @@ -0,0 +1,19 @@ +/* + Mixin that provides methods for a login route based on OSF cookie authentication + This auth method is not available to third-party applications + + Sample code and structure based on documentation for https://github.com/simplabs/ember-simple-auth + */ + +import Ember from 'ember'; + +export default Ember.Mixin.create({ + session: Ember.inject.service('session'), + + actions: { + loginHandler: function () { + console.log('Called submit', ...arguments); + return true; + } + } +}); diff --git a/tests/dummy/app/controllers/cookielogin.js b/tests/dummy/app/controllers/cookielogin.js index 517cacbe6..19f812476 100644 --- a/tests/dummy/app/controllers/cookielogin.js +++ b/tests/dummy/app/controllers/cookielogin.js @@ -1,10 +1,6 @@ import Ember from 'ember'; -export default Ember.Controller.extend({ - actions: { - loginHandler: function () { - console.log('Called submit', ...arguments); - return true; - } - } +import OsfCookieLoginController from 'ember-osf/mixins/osf-cookie-login-controller'; + +export default Ember.Controller.extend(OsfCookieLoginController, { }); diff --git a/tests/dummy/app/routes/cookielogin.js b/tests/dummy/app/routes/cookielogin.js index 2251e8c10..640a5bac0 100644 --- a/tests/dummy/app/routes/cookielogin.js +++ b/tests/dummy/app/routes/cookielogin.js @@ -1,13 +1,5 @@ import Ember from 'ember'; -import OsfCookieLoginRoute from 'ember-osf/mixins/osf-cookie-login-route'; - -export default Ember.Route.extend(OsfCookieLoginRoute , { - - // actions: { - // loginHandler: function(){ - // return true; - // } - // } +export default Ember.Route.extend({ }); diff --git a/tests/integration/components/login-form-test.js b/tests/integration/components/login-form-test.js new file mode 100644 index 000000000..abfe9c141 --- /dev/null +++ b/tests/integration/components/login-form-test.js @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('login-form', 'Integration | Component | login form', { + integration: true +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.render(hbs`{{login-form}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#login-form}} + template block text + {{/login-form}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); diff --git a/tests/unit/mixins/osf-cookie-login-controller-test.js b/tests/unit/mixins/osf-cookie-login-controller-test.js new file mode 100644 index 000000000..73fdad97b --- /dev/null +++ b/tests/unit/mixins/osf-cookie-login-controller-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import OsfCookieLoginControllerMixin from 'ember-osf/mixins/osf-cookie-login-controller'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | osf cookie login controller'); + +// Replace this with your real tests. +test('it works', function(assert) { + let OsfCookieLoginControllerObject = Ember.Object.extend(OsfCookieLoginControllerMixin); + let subject = OsfCookieLoginControllerObject.create(); + assert.ok(subject); +}); From 4bcc5810fa748bd089210f939fb795c44ea2b7f5 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Mon, 16 May 2016 15:02:40 -0400 Subject: [PATCH 167/959] Finish boilerplate --- addon/components/login-form.js | 5 +++- .../integration/components/login-form-test.js | 24 ------------------- 2 files changed, 4 insertions(+), 25 deletions(-) delete mode 100644 tests/integration/components/login-form-test.js diff --git a/addon/components/login-form.js b/addon/components/login-form.js index 612f728fb..b49a4a80c 100644 --- a/addon/components/login-form.js +++ b/addon/components/login-form.js @@ -5,7 +5,10 @@ import layout from '../templates/components/login-form'; // TODO: Future reading- add responsiveness on delays http://blog.trackets.com/2013/05/23/how-to-write-a-login-form.html export default Ember.Component.extend({ layout, - + + identification: undefined, + password: undefined, + actions: { loginSubmit() { this.sendAction('loginSubmit', ...arguments); diff --git a/tests/integration/components/login-form-test.js b/tests/integration/components/login-form-test.js deleted file mode 100644 index abfe9c141..000000000 --- a/tests/integration/components/login-form-test.js +++ /dev/null @@ -1,24 +0,0 @@ -import { moduleForComponent, test } from 'ember-qunit'; -import hbs from 'htmlbars-inline-precompile'; - -moduleForComponent('login-form', 'Integration | Component | login form', { - integration: true -}); - -test('it renders', function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.on('myAction', function(val) { ... }); - - this.render(hbs`{{login-form}}`); - - assert.equal(this.$().text().trim(), ''); - - // Template block usage: - this.render(hbs` - {{#login-form}} - template block text - {{/login-form}} - `); - - assert.equal(this.$().text().trim(), 'template block text'); -}); From bbbc0da84242b088b904092cca436ea4b6d1b634 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Mon, 16 May 2016 16:48:41 -0400 Subject: [PATCH 168/959] File manager work, add actions to file page [skip ci] --- addon/models/file-provider.js | 3 +- addon/models/file.js | 10 +-- addon/services/file-manager.js | 46 ++++++----- .../app/components/files-tree/component.js | 3 +- .../app/components/files-tree/template.hbs | 14 +++- tests/dummy/app/routes/file.js | 51 +++++++++++++ tests/dummy/app/templates/file.hbs | 76 ++++++++++++------- 7 files changed, 142 insertions(+), 61 deletions(-) diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index ac66b3e9c..dccf7e622 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -1,11 +1,10 @@ import Ember from 'ember'; import DS from 'ember-data'; - import OsfModel from 'ember-osf/models/base'; export default OsfModel.extend({ - kind: DS.attr('string'), name: DS.attr('string'), + kind: DS.attr('string'), path: DS.attr('string'), provider: DS.attr('string'), files: DS.hasMany('file'), diff --git a/addon/models/file.js b/addon/models/file.js index 2c53ebe97..aacc88efe 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -18,22 +18,20 @@ export default OsfModel.extend({ path: DS.attr('string'), size: DS.attr('number'), provider: DS.attr('string'), - materializedPath: DS.attr('string'), lastTouched: DS.attr('date'), dateModified: DS.attr('date'), dateCreated: DS.attr('date'), - - checkout: DS.attr(), extra: DS.attr(), + parentFolder: DS.belongsTo('file', { inverse: 'files' }), + isFolder: Ember.computed.equal('kind', 'folder'), + // Folder attributes files: DS.hasMany('file', { inverse: 'parentFolder' }), // File attributes versions: DS.hasMany('file-version'), comments: DS.hasMany('comment'), - - parentFolder: DS.belongsTo('file', { inverse: 'files' }), - isFolder: Ember.computed.equal('kind', 'folder'), + checkout: DS.attr(), }); diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index 8d6589974..2cfc26bbb 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -1,7 +1,8 @@ import Ember from 'ember'; export default Ember.Service.extend({ - session: Ember.inject.service('session'), + session: Ember.inject.service(), + store: Ember.inject.service(), // File actions getContents(file) { @@ -24,17 +25,18 @@ export default Ember.Service.extend({ // Folder actions addSubfolder(folder, name) { var url = folder.get('links').new_folder; + var params = { + name, + kind: 'folder' + }; // HACK: This is the only link that already has a query string if (url.search(/\?kind=folder$/) > -1) { url = `${url}&name=${name}`; - return this._waterbutlerRequest('PUT', url); - } else { - return this._waterbutlerRequest('PUT', url, { - name, - kind: 'folder' - }); + params = undefined; } + + return this._waterbutlerRequest('PUT', url, params); }, uploadFile(folder, name, contents) { @@ -48,14 +50,12 @@ export default Ember.Service.extend({ // File and folder actions rename(file, newName) { var url = file.get('links').move; - return this._waterbutlerRequest('POST', url, data = { - action: 'rename', - rename: newName - }); + return this._waterbutlerRequest('POST', url, null, + JSON.stringify({ action: 'rename', rename: newName })); }, - move(file, targetFolder, newName=null, replace=true, node=null, - provider=null, action='move') { + move(file, targetFolder, newName=null, replace=true, + node=null, provider=null, action='move') { var url = file.get('links').move; var data = { action, @@ -75,38 +75,42 @@ export default Ember.Service.extend({ if (provider) { data.provider = provider; } - return this._waterbutlerRequest('POST', url, data=data); + return this._waterbutlerRequest('POST', url, null, data); }, - copy(file, targetFolder, newName=null, - replace=true, node=null, provider=null) { + copy(file, targetFolder, newName=null, replace=true, + node=null, provider=null) { return this.move(file, targetFolder, newName, replace, node, provider, 'copy'); }, deleteFile(file) { - var url = folder.get('links').delete; + var url = file.get('links').delete; return this._waterbutlerRequest('DELETE', url); }, _waterbutlerRequest(method, url, queryParams=null, data=null) { + if (!url) { + return Ember.RSVP.Promise.reject('That file/folder has no link for that action!'); + } if (queryParams) { let queryString = Ember.$.param(queryParams); url = `${url}?${queryString}`; } - var sessionData = this.get('session').get('data'); - var accessToken = sessionData.authenticated.attributes.accessToken; + var sessionData = this.get('session').get('data').authenticated; + var accessToken = sessionData.attributes.accessToken; return new Ember.RSVP.Promise(function(resolve, reject) { Ember.$.ajax(url, { method, + data, headers: { Authorization: `Bearer ${accessToken}` }, error(_, __, errorMsg) { reject(new Error(errorMsg)); }, - success(data) { - resolve(data); + success(response) { + resolve(response); } }); }); diff --git a/tests/dummy/app/components/files-tree/component.js b/tests/dummy/app/components/files-tree/component.js index 44bf16cc0..c7503972a 100644 --- a/tests/dummy/app/components/files-tree/component.js +++ b/tests/dummy/app/components/files-tree/component.js @@ -2,5 +2,6 @@ import Ember from 'ember'; import layout from './template'; export default Ember.Component.extend({ - layout + layout, + fileManager: Ember.inject.service() }); diff --git a/tests/dummy/app/components/files-tree/template.hbs b/tests/dummy/app/components/files-tree/template.hbs index 4589ecb3b..99a516d67 100644 --- a/tests/dummy/app/components/files-tree/template.hbs +++ b/tests/dummy/app/components/files-tree/template.hbs @@ -1,12 +1,18 @@

{{#if model.isFolder}} -

+ ({{link-to 'folder details' 'file' model}}) +

    {{#each model.files as |file|}} - {{files-tree model=file}} +
  • + {{file.name}} + ({{#link-to 'file' file}}{{file.kind}} details{{/link-to}}) +
  • + {{else}} +
  • (empty)
  • {{/each}} -

    +
{{else}} - ({{link-to 'details' 'file' model}}) + ({{link-to 'file details' 'file' model}}) {{/if}}

diff --git a/tests/dummy/app/routes/file.js b/tests/dummy/app/routes/file.js index 32b35b0e8..89e66e95c 100644 --- a/tests/dummy/app/routes/file.js +++ b/tests/dummy/app/routes/file.js @@ -2,7 +2,58 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; export default Ember.Route.extend(AuthenticatedRouteMixin, { + fileManager: Ember.inject.service(), + model(params) { + // File provider IDs are 'nodeid:provider' + if (params.file_id.includes(':')) { + let [node_id, provider] = params.file_id.split(':'); + let node = this.store.findRecord('node', node_id); + if (node) { + let files = node.get('files'); + let name = node.get('name'); + if (files) { + return files.findBy('provider', provider); + } + } + } + return this.store.findRecord('file', params.file_id); + }, + + actions: { + addSubfolder(name) { + if (name) { + var folder = this.modelFor(this.routeName); + var p = this.get('fileManager').addSubfolder(folder, name); + p.then(() => { + this.store.unloadRecord(folder); + this.refresh(); + }); + } + }, + + uploadFile() { + }, + + rename(newName) { + if (newName) { + var file = this.modelFor(this.routeName); + var p = this.get('fileManager').rename(file, newName); + p.then(() => { + file.set('name', newName); + this.refresh(); + }); + } + }, + + deleteFile() { + var file = this.modelFor(this.routeName); + var p = this.get('fileManager').deleteFile(file); + p.then(() => { + this.store.unloadRecord(file); + this.refresh(); + }); + } } }); diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs index b00d399d7..3eddb05a8 100644 --- a/tests/dummy/app/templates/file.hbs +++ b/tests/dummy/app/templates/file.hbs @@ -1,10 +1,8 @@
-

File detail

-

{{model.name}}

+

File detail: {{model.name}}

{{model.kind}}

-

{{model.path}}

-

{{model.size}}

{{model.provider}}

+

{{model.path}}

{{model.materializedPath}}

{{model.lastTouched}}

{{model.dateModified}}

@@ -12,28 +10,52 @@

{{model.checkout}}


-

Versions

-
    - {{#each model.versions as |version|}} -
  • -
    {{version.id}}
    -
    {{version.size}}
    -
    {{version.contentType}}
    -
  • - {{else}} - (none) - {{/each}} -
-
-

Comments

-
    - {{#each model.comments as |comment|}} -
  • -
    {{comment.content}}
    -
  • + +

    Actions

    +

    + Rename: {{input value=newName}} + +

    +

    + Delete: +

    + {{#if model.isFolder}} +

    + New folder: {{input value=newFolderName}} + +

    + +
    +

    Files

    + {{files-tree model=model}} {{else}} - (none) - {{/each}} -
- +
+

Versions

+
    + {{#each model.versions as |version|}} +
  • +
    {{version.id}}
    +
    {{version.size}}
    +
    {{version.contentType}}
    +
  • + {{else}} + (none) + {{/each}} +
+
+

Comments

+
    + {{#each model.comments as |comment|}} +
  • + + {{comment.content}} +
  • + {{else}} + (none) + {{/each}} +
+ {{/if}}
From e100118820174c2e607f9f89197a9115a45ab48f Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Mon, 16 May 2016 17:11:06 -0400 Subject: [PATCH 169/959] Make file detail route nested under node route [skip ci] --- tests/dummy/app/router.js | 13 ++++++++++--- tests/dummy/app/routes/nodes/detail/files.js | 4 ++++ .../dummy/app/routes/nodes/detail/files/provider.js | 4 ++++ .../{ => nodes/detail/files/provider}/file.js | 0 tests/dummy/app/templates/nodes/detail/files.hbs | 1 + .../app/templates/nodes/detail/files/provider.hbs | 1 + .../{ => nodes/detail/files/provider}/file.hbs | 0 7 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/dummy/app/routes/nodes/detail/files.js create mode 100644 tests/dummy/app/routes/nodes/detail/files/provider.js rename tests/dummy/app/routes/{ => nodes/detail/files/provider}/file.js (100%) create mode 100644 tests/dummy/app/templates/nodes/detail/files.hbs create mode 100644 tests/dummy/app/templates/nodes/detail/files/provider.hbs rename tests/dummy/app/templates/{ => nodes/detail/files/provider}/file.hbs (100%) diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 216e91a03..b260e0306 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -12,6 +12,16 @@ Router.map(function() { this.route('nodes', function() { this.route('detail', { path: '/:node_id' + }, function() { + this.route('files', function() { + this.route('provider', { + path: '/:provider' + }, function() { + this.route('file', { + path: '/:file_id' + }); + }); + }); }); }); this.route('login'); @@ -30,9 +40,6 @@ Router.map(function() { path: '/:user_id' }); }); - this.route('file', { - path: '/file/:file_id' - }); }); export default Router; diff --git a/tests/dummy/app/routes/nodes/detail/files.js b/tests/dummy/app/routes/nodes/detail/files.js new file mode 100644 index 000000000..26d9f3124 --- /dev/null +++ b/tests/dummy/app/routes/nodes/detail/files.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ +}); diff --git a/tests/dummy/app/routes/nodes/detail/files/provider.js b/tests/dummy/app/routes/nodes/detail/files/provider.js new file mode 100644 index 000000000..26d9f3124 --- /dev/null +++ b/tests/dummy/app/routes/nodes/detail/files/provider.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ +}); diff --git a/tests/dummy/app/routes/file.js b/tests/dummy/app/routes/nodes/detail/files/provider/file.js similarity index 100% rename from tests/dummy/app/routes/file.js rename to tests/dummy/app/routes/nodes/detail/files/provider/file.js diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/files.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/tests/dummy/app/templates/nodes/detail/files/provider.hbs b/tests/dummy/app/templates/nodes/detail/files/provider.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/files/provider.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs similarity index 100% rename from tests/dummy/app/templates/file.hbs rename to tests/dummy/app/templates/nodes/detail/files/provider/file.hbs From c777f055ff7cf1dc3cbb0689c307ef1cc7ebf01f Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 17:36:26 -0400 Subject: [PATCH 170/959] Add add contributor form to nodes detail template. --- tests/dummy/app/templates/nodes/detail.hbs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index bdee11b0d..0a8802595 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -22,16 +22,32 @@ + {{#each model.contributors as |contrib|}} + {{/each}}
ID Permissions Author?
{{contrib.id}} {{contrib.permission}} {{contrib.bibliographic}}
+

Add contributor

+ {{input value=contributorID}}
+ +
+ {{radio-button name="permission" value="read" checked=contributorPermissions}} Read
+ {{radio-button name="permission" value="write" checked=contributorPermissions}} Read + Write
+ {{radio-button name="permission" value="admin" checked=contributorPermissions}} Administrator
+ +
+ {{radio-button name="bibliographic" value=1 checked=bibliographic}} Bibliographic
+ {{radio-button name="bibliographic" value=0 checked=bibliographic}} Non-Bibliographic
+ + +

From 484b2c2666cf0e2592ebe6e8dac9880d834e5643 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 17:36:57 -0400 Subject: [PATCH 171/959] Add addContributor action to nodes detail route. --- tests/dummy/app/routes/nodes/detail.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index e1ea35f24..1d9c8fcab 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -21,6 +21,20 @@ export default Ember.Route.extend({ } else { console.log('You do not have permissions to edit this node'); } + }, + addContributor(contribId, permission, bibliographic) { + var node = this.modelFor(this.routeName); + if (node.get('currentUserPermissions').indexOf('admin') !== -1) { + var contributor = this.store.createRecord('contributor', { + id: contribId, + permission: permission, + bibliographic: bibliographic, + nodeId: node.id + }); + contributor.save(); + } else { + console.log('You do not have permissions to add contributors'); + } } } From ac17b3426917c8cb3005fa314ea8c2179441a91b Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 17:37:43 -0400 Subject: [PATCH 172/959] Add nodeId field to contributor model so nodeId is accessible in adapter. --- addon/models/contributor.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addon/models/contributor.js b/addon/models/contributor.js index 8d469b953..7cde98ffb 100644 --- a/addon/models/contributor.js +++ b/addon/models/contributor.js @@ -5,5 +5,6 @@ import OsfModel from '../mixins/osf-model'; export default DS.Model.extend(OsfModel, { bibliographic: DS.attr('boolean'), permission: DS.attr('string'), - users: DS.hasMany('user') + users: DS.hasMany('user'), + nodeId: DS.attr('string') }); From 5c8cb6c5dc56bfbb47993b0669a7a303b7da6289 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 17:38:34 -0400 Subject: [PATCH 173/959] Modify contributor adapter to change url from /contributors/ to nodes/node_id/contributors. --- addon/adapters/contributor.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addon/adapters/contributor.js b/addon/adapters/contributor.js index 5a903d089..59f67af4e 100644 --- a/addon/adapters/contributor.js +++ b/addon/adapters/contributor.js @@ -1,4 +1,11 @@ import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ + buildURL(_, __, snap) { + // Modifies URL from /contributors to nodes//contributors/ to match APIv2 route for creating contributors. + var base = this._super(...arguments); + var ar = base.split('/'); + ar.splice(4, 0, 'nodes/' + snap._attributes.nodeId); + return ar.join('/'); + } }); From 6a0bfdaa9a5f0fc72392bb2a29fa2a906f76d31b Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 17:39:05 -0400 Subject: [PATCH 174/959] Modify contributor serializer so user id is sent under "relationships". --- addon/serializers/contributor.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addon/serializers/contributor.js b/addon/serializers/contributor.js index c5617e1d4..2d1aef3e5 100644 --- a/addon/serializers/contributor.js +++ b/addon/serializers/contributor.js @@ -1,4 +1,17 @@ import OsfSerializer from './osf-serializer'; export default OsfSerializer.extend({ + serialize: function(snapshot, options) { + // Restore relationships to serialized data + var serialized = this._super(snapshot, options); + serialized.data.relationships = { + users: { + data: { + id: serialized.data.id, + type: 'users' + } + } + }; + return serialized; + }, }); From 337545ac2c62aa30838d72a76ff0f37a5363c038 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 16 May 2016 17:46:04 -0400 Subject: [PATCH 175/959] Add comment. --- addon/serializers/contributor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addon/serializers/contributor.js b/addon/serializers/contributor.js index 2d1aef3e5..4cc012c2d 100644 --- a/addon/serializers/contributor.js +++ b/addon/serializers/contributor.js @@ -4,6 +4,7 @@ export default OsfSerializer.extend({ serialize: function(snapshot, options) { // Restore relationships to serialized data var serialized = this._super(snapshot, options); + // APIv2 expects contributor information to be nested under relationships. serialized.data.relationships = { users: { data: { From 5ad76f20da035de556692ae6570cf77d58f93bb7 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 17 May 2016 09:56:57 -0400 Subject: [PATCH 176/959] Rename login route mixin to disambiguate --- .../mixins/{osf-login-route.js => osf-token-login-route.js} | 0 tests/dummy/app/routes/login.js | 4 ++-- ...sf-login-route-test.js => osf-token-login-route-test.js} | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename addon/mixins/{osf-login-route.js => osf-token-login-route.js} (100%) rename tests/unit/mixins/{osf-login-route-test.js => osf-token-login-route-test.js} (51%) diff --git a/addon/mixins/osf-login-route.js b/addon/mixins/osf-token-login-route.js similarity index 100% rename from addon/mixins/osf-login-route.js rename to addon/mixins/osf-token-login-route.js diff --git a/tests/dummy/app/routes/login.js b/tests/dummy/app/routes/login.js index 8dd12d294..e26b21657 100644 --- a/tests/dummy/app/routes/login.js +++ b/tests/dummy/app/routes/login.js @@ -1,4 +1,4 @@ import Ember from 'ember'; -import OsfLoginRouteMixin from 'ember-osf/mixins/osf-login-route'; +import OsfTokenLoginRouteMixin from 'ember-osf/mixins/osf-token-login-route'; -export default Ember.Route.extend(OsfLoginRouteMixin); +export default Ember.Route.extend(OsfTokenLoginRouteMixin); diff --git a/tests/unit/mixins/osf-login-route-test.js b/tests/unit/mixins/osf-token-login-route-test.js similarity index 51% rename from tests/unit/mixins/osf-login-route-test.js rename to tests/unit/mixins/osf-token-login-route-test.js index 44df88811..8c2f57d18 100644 --- a/tests/unit/mixins/osf-login-route-test.js +++ b/tests/unit/mixins/osf-token-login-route-test.js @@ -1,12 +1,12 @@ import Ember from 'ember'; -import OsfLoginRouteMixin from '../../../mixins/osf-login-route'; +import OsfTokenLoginRouteMixin from '../../../mixins/osf-token-login-route'; import { module, test } from 'qunit'; -module('Unit | Mixin | osf login route'); +module('Unit | Mixin | osf token login route'); // Replace this with your real tests. test('it works', function(assert) { - let OsfLoginRouteObject = Ember.Object.extend(OsfLoginRouteMixin); + let OsfLoginRouteObject = Ember.Object.extend(OsfTokenLoginRouteMixin); let subject = OsfLoginRouteObject.create(); assert.ok(subject); }); From 0f945f910fa2ec57592df32c0632c8f477657992 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 17 May 2016 10:27:46 -0400 Subject: [PATCH 177/959] Rename remaining token login pages [ci skip] --- ...sf-login-controller.js => osf-token-login-controller.js} | 0 app/mixins/osf-login-controller.js | 1 - app/mixins/osf-login-route.js | 1 - app/mixins/osf-token-login-controller.js | 1 + app/mixins/osf-token-login-route.js | 1 + tests/dummy/app/controllers/login.js | 4 ++-- tests/unit/mixins/osf-login-controller-test.js | 6 +++--- 7 files changed, 7 insertions(+), 7 deletions(-) rename addon/mixins/{osf-login-controller.js => osf-token-login-controller.js} (100%) delete mode 100644 app/mixins/osf-login-controller.js delete mode 100644 app/mixins/osf-login-route.js create mode 100644 app/mixins/osf-token-login-controller.js create mode 100644 app/mixins/osf-token-login-route.js diff --git a/addon/mixins/osf-login-controller.js b/addon/mixins/osf-token-login-controller.js similarity index 100% rename from addon/mixins/osf-login-controller.js rename to addon/mixins/osf-token-login-controller.js diff --git a/app/mixins/osf-login-controller.js b/app/mixins/osf-login-controller.js deleted file mode 100644 index 92cf3f6b4..000000000 --- a/app/mixins/osf-login-controller.js +++ /dev/null @@ -1 +0,0 @@ -export {default} from 'ember-osf/mixins/osf-login-controller'; diff --git a/app/mixins/osf-login-route.js b/app/mixins/osf-login-route.js deleted file mode 100644 index fc97a87ea..000000000 --- a/app/mixins/osf-login-route.js +++ /dev/null @@ -1 +0,0 @@ -export {default} from 'ember-osf/mixins/osf-login-route'; diff --git a/app/mixins/osf-token-login-controller.js b/app/mixins/osf-token-login-controller.js new file mode 100644 index 000000000..d4bd25a72 --- /dev/null +++ b/app/mixins/osf-token-login-controller.js @@ -0,0 +1 @@ +export {default} from 'ember-osf/mixins/osf-token-login-controller'; diff --git a/app/mixins/osf-token-login-route.js b/app/mixins/osf-token-login-route.js new file mode 100644 index 000000000..1246a002c --- /dev/null +++ b/app/mixins/osf-token-login-route.js @@ -0,0 +1 @@ +export {default} from 'ember-osf/mixins/osf-token-login-route'; diff --git a/tests/dummy/app/controllers/login.js b/tests/dummy/app/controllers/login.js index 5b1f6bac5..9d687209b 100644 --- a/tests/dummy/app/controllers/login.js +++ b/tests/dummy/app/controllers/login.js @@ -1,5 +1,5 @@ import Ember from 'ember'; -import OsfLoginControllerMixin from 'ember-osf/mixins/osf-login-controller'; +import OsfTokenLoginControllerMixin from 'ember-osf/mixins/osf-token-login-controller'; -export default Ember.Controller.extend(OsfLoginControllerMixin); +export default Ember.Controller.extend(OsfTokenLoginControllerMixin); diff --git a/tests/unit/mixins/osf-login-controller-test.js b/tests/unit/mixins/osf-login-controller-test.js index 2661b3397..0c5ca65f0 100644 --- a/tests/unit/mixins/osf-login-controller-test.js +++ b/tests/unit/mixins/osf-login-controller-test.js @@ -1,12 +1,12 @@ import Ember from 'ember'; -import OsfLoginControllerMixin from '../../../mixins/osf-login-controller'; +import OsfTokenLoginControllerMixin from '../../../mixins/osf-token-login-controller'; import { module, test } from 'qunit'; -module('Unit | Mixin | osf login controller'); +module('Unit | Mixin | osf token login controller'); // Replace this with your real tests. test('it works', function(assert) { - let OsfLoginControllerObject = Ember.Object.extend(OsfLoginControllerMixin); + let OsfLoginControllerObject = Ember.Object.extend(OsfTokenLoginControllerMixin); let subject = OsfLoginControllerObject.create(); assert.ok(subject); }); From a08576910cbd952d1cb80929716d83228c5685ba Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Tue, 17 May 2016 13:43:30 -0400 Subject: [PATCH 178/959] Add sign-up component --- .../dummy/app/components/sign-up/component.js | 6 ++ .../dummy/app/components/sign-up/template.hbs | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/dummy/app/components/sign-up/component.js create mode 100644 tests/dummy/app/components/sign-up/template.hbs diff --git a/tests/dummy/app/components/sign-up/component.js b/tests/dummy/app/components/sign-up/component.js new file mode 100644 index 000000000..8ef0d629f --- /dev/null +++ b/tests/dummy/app/components/sign-up/component.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; +import layout from './template'; + +export default Ember.Component.extend({ + layout +}); diff --git a/tests/dummy/app/components/sign-up/template.hbs b/tests/dummy/app/components/sign-up/template.hbs new file mode 100644 index 000000000..80ffbd7f3 --- /dev/null +++ b/tests/dummy/app/components/sign-up/template.hbs @@ -0,0 +1,58 @@ + \ No newline at end of file From c9acfda7af451e60d8e32b67f5b87a608779f298 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 17 May 2016 14:17:55 -0400 Subject: [PATCH 179/959] Add remove contributor buttons to node detail template. --- tests/dummy/app/templates/nodes/detail.hbs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 0a8802595..4130e928d 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -23,17 +23,21 @@ - + + {{#each model.contributors as |contrib|}} + {{/each}}
ID Permissions Author?Bibliographic
{{contrib.id}} {{contrib.permission}} {{contrib.bibliographic}}
+


+

Add contributor

{{input value=contributorID}}
@@ -42,11 +46,13 @@ {{radio-button name="permission" value="write" checked=contributorPermissions}} Read + Write
{{radio-button name="permission" value="admin" checked=contributorPermissions}} Administrator
-
+
{{radio-button name="bibliographic" value=1 checked=bibliographic}} Bibliographic
{{radio-button name="bibliographic" value=0 checked=bibliographic}} Non-Bibliographic
- +
+ +

@@ -59,6 +65,8 @@

+
+

Files

{{#each model.files as |provider|}} {{files-tree model=provider}} From dc4b36da454d022d1c039363a162d793f510aec7 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 17 May 2016 14:19:32 -0400 Subject: [PATCH 180/959] Add action for deleting contributor as well as helper methods to determine if contributor can be deleted. --- tests/dummy/app/routes/nodes/detail.js | 58 +++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 1d9c8fcab..29eff437c 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -1,6 +1,7 @@ import Ember from 'ember'; export default Ember.Route.extend({ + model(params) { return this.store.findRecord('node', params.node_id); }, @@ -32,10 +33,65 @@ export default Ember.Route.extend({ nodeId: node.id }); contributor.save(); + console.log('Contributor added.'); } else { console.log('You do not have permissions to add contributors'); } + }, + deleteContributor(contrib) { + var node = this.modelFor(this.routeName); + contrib.setProperties({ nodeId: node.id }); + let user = this.modelFor('application'); + + var contribMap = node.get('contributors').content.currentState.reduce(function(newMap, contrib) { + newMap[contrib.id] = { permission: contrib._data.permission, bibliographic: contrib._data.bibliographic }; + return newMap; + }, {}); + + if (node.get('currentUserPermissions').indexOf('admin') !== -1) { + this.attemptContributorRemoval(contrib, contribMap, node); + } else { + // Non-admins can only attempt to remove themselves as contributors + if (contrib.id === user.id) { + this.attemptContributorRemoval(contrib, contribMap, node); + } else { + console.log('Non-admins cannot delete other contributors.'); + } + } } - } + }, + canRemoveContributor(contribRemoving, contribMap) { + /** Contributor can only be removed if there is at least one other contributor + with admin permissions, and at least one other bibliographic contributor **/ + var bibliographic = false; + var admin = false; + for (var contribId in contribMap) { + if (contribId === contribRemoving.id) { + continue; + } else { + if (contribMap[contribId].bibliographic) { + bibliographic = true; + } + if (contribMap[contribId].permission === 'admin') { + admin = true; + } + } + } + if (bibliographic && admin) { + return true; + } + return false; + }, + attemptContributorRemoval(contrib, contribMap, node) { + if (this.canRemoveContributor(contrib, contribMap)) { + node.get('contributors').removeObject(contrib); + contrib.deleteRecord(); + node.save(); + contrib.save(); + console.log('Contributor removed.'); + } else { + console.log('Cannot remove contributor'); + } + } }); From ab6ad2b2f5f3e04af95400f974d0cfb610567d24 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 17 May 2016 14:51:08 -0400 Subject: [PATCH 181/959] Require contributor id to be specified. --- tests/dummy/app/routes/nodes/detail.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 29eff437c..fecc0ee56 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -25,17 +25,21 @@ export default Ember.Route.extend({ }, addContributor(contribId, permission, bibliographic) { var node = this.modelFor(this.routeName); - if (node.get('currentUserPermissions').indexOf('admin') !== -1) { - var contributor = this.store.createRecord('contributor', { - id: contribId, - permission: permission, - bibliographic: bibliographic, - nodeId: node.id - }); - contributor.save(); - console.log('Contributor added.'); + if (contribId) { + if (node.get('currentUserPermissions').indexOf('admin') !== -1) { + var contributor = this.store.createRecord('contributor', { + id: contribId, + permission: permission, + bibliographic: bibliographic, + nodeId: node.id + }); + contributor.save(); + console.log('Contributor added.'); + } else { + console.log('You do not have permissions to add contributors'); + } } else { - console.log('You do not have permissions to add contributors'); + console.log('User ID must be specified.'); } }, deleteContributor(contrib) { From b02d1b1a59c73ffd25bb3be2c8ace3e64915e54b Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Tue, 17 May 2016 15:02:14 -0400 Subject: [PATCH 182/959] Move a couple files [skip ci] --- tests/dummy/app/routes/nodes/detail/files.js | 4 +++ .../app/routes/nodes/detail/files/provider.js | 4 +++ .../nodes/detail/files/provider/file.js | 34 +++++++------------ .../nodes/{detail.hbs => detail/index.hbs} | 0 4 files changed, 20 insertions(+), 22 deletions(-) rename tests/dummy/app/templates/nodes/{detail.hbs => detail/index.hbs} (100%) diff --git a/tests/dummy/app/routes/nodes/detail/files.js b/tests/dummy/app/routes/nodes/detail/files.js index 26d9f3124..c8668df6f 100644 --- a/tests/dummy/app/routes/nodes/detail/files.js +++ b/tests/dummy/app/routes/nodes/detail/files.js @@ -1,4 +1,8 @@ import Ember from 'ember'; export default Ember.Route.extend({ + model() { + var node = this.modelFor('nodes/detail'); + return node.get('files'); + }, }); diff --git a/tests/dummy/app/routes/nodes/detail/files/provider.js b/tests/dummy/app/routes/nodes/detail/files/provider.js index 26d9f3124..6ddd95d7c 100644 --- a/tests/dummy/app/routes/nodes/detail/files/provider.js +++ b/tests/dummy/app/routes/nodes/detail/files/provider.js @@ -1,4 +1,8 @@ import Ember from 'ember'; export default Ember.Route.extend({ + model(params) { + var fileProviders = this.modelFor('nodes/detail/files'); + return fileProviders.findBy('provider', params.provider); + }, }); diff --git a/tests/dummy/app/routes/nodes/detail/files/provider/file.js b/tests/dummy/app/routes/nodes/detail/files/provider/file.js index 89e66e95c..868df65b7 100644 --- a/tests/dummy/app/routes/nodes/detail/files/provider/file.js +++ b/tests/dummy/app/routes/nodes/detail/files/provider/file.js @@ -5,27 +5,15 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { fileManager: Ember.inject.service(), model(params) { - // File provider IDs are 'nodeid:provider' - if (params.file_id.includes(':')) { - let [node_id, provider] = params.file_id.split(':'); - let node = this.store.findRecord('node', node_id); - if (node) { - let files = node.get('files'); - let name = node.get('name'); - if (files) { - return files.findBy('provider', provider); - } - } - } - + // TODO: verify that this file actually belongs to the parent node? return this.store.findRecord('file', params.file_id); }, actions: { addSubfolder(name) { - if (name) { - var folder = this.modelFor(this.routeName); - var p = this.get('fileManager').addSubfolder(folder, name); + let folder = this.modelFor(this.routeName); + if (name && folder.get('isFolder')) { + let p = this.get('fileManager').addSubfolder(folder, name); p.then(() => { this.store.unloadRecord(folder); this.refresh(); @@ -37,9 +25,9 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { }, rename(newName) { - if (newName) { - var file = this.modelFor(this.routeName); - var p = this.get('fileManager').rename(file, newName); + let file = this.modelFor(this.routeName); + if (newName && newName !== file.get('name')) { + let p = this.get('fileManager').rename(file, newName); p.then(() => { file.set('name', newName); this.refresh(); @@ -48,11 +36,13 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { }, deleteFile() { - var file = this.modelFor(this.routeName); - var p = this.get('fileManager').deleteFile(file); + let file = this.modelFor(this.routeName); + let p = this.get('fileManager').deleteFile(file); p.then(() => { this.store.unloadRecord(file); - this.refresh(); + let node = this.modelFor('nodes.detail'); + this.replaceWith('nodes.detail.files.provider', + node, file.get('provider')); }); } } diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs similarity index 100% rename from tests/dummy/app/templates/nodes/detail.hbs rename to tests/dummy/app/templates/nodes/detail/index.hbs From f3cddffecf81ac15b94b7ad41e29d67420f54b78 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Tue, 17 May 2016 15:02:49 -0400 Subject: [PATCH 183/959] Functioning file navigation and basic management [skip ci] --- addon/models/file-provider.js | 1 + addon/models/file.js | 1 + .../app/components/file-actions/component.js | 45 +++++++++++++++++++ .../app/components/file-actions/template.hbs | 19 ++++++++ .../app/components/files-tree/component.js | 1 - .../app/components/files-tree/template.hbs | 23 +++++----- .../nodes/detail/files/provider/file.js | 10 +++++ .../nodes/detail/files/provider/index.js | 9 ++++ tests/dummy/app/routes/nodes/detail/files.js | 13 ++++-- .../app/routes/nodes/detail/files/provider.js | 5 ++- .../nodes/detail/files/provider/file.js | 44 +++--------------- tests/dummy/app/templates/nodes/detail.hbs | 1 + .../app/templates/nodes/detail/files.hbs | 4 ++ .../templates/nodes/detail/files/index.hbs | 6 +++ .../nodes/detail/files/provider/file.hbs | 28 +++++------- .../nodes/detail/files/provider/index.hbs | 13 ++++++ .../app/templates/nodes/detail/index.hbs | 7 ++- 17 files changed, 152 insertions(+), 78 deletions(-) create mode 100644 tests/dummy/app/components/file-actions/component.js create mode 100644 tests/dummy/app/components/file-actions/template.hbs create mode 100644 tests/dummy/app/controllers/nodes/detail/files/provider/file.js create mode 100644 tests/dummy/app/controllers/nodes/detail/files/provider/index.js create mode 100644 tests/dummy/app/templates/nodes/detail.hbs create mode 100644 tests/dummy/app/templates/nodes/detail/files/index.hbs create mode 100644 tests/dummy/app/templates/nodes/detail/files/provider/index.hbs diff --git a/addon/models/file-provider.js b/addon/models/file-provider.js index dccf7e622..c364be8b7 100644 --- a/addon/models/file-provider.js +++ b/addon/models/file-provider.js @@ -11,4 +11,5 @@ export default OsfModel.extend({ node: DS.belongsTo('node'), isFolder: Ember.computed.equal('kind', 'folder'), + isProvider: true }); diff --git a/addon/models/file.js b/addon/models/file.js index aacc88efe..9c27733f6 100644 --- a/addon/models/file.js +++ b/addon/models/file.js @@ -26,6 +26,7 @@ export default OsfModel.extend({ parentFolder: DS.belongsTo('file', { inverse: 'files' }), isFolder: Ember.computed.equal('kind', 'folder'), + isProvider: false, // Folder attributes files: DS.hasMany('file', { inverse: 'parentFolder' }), diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js new file mode 100644 index 000000000..145e0e652 --- /dev/null +++ b/tests/dummy/app/components/file-actions/component.js @@ -0,0 +1,45 @@ +import Ember from 'ember'; +import layout from './template'; + +export default Ember.Component.extend({ + layout, + fileManager: Ember.inject.service(), + store: Ember.inject.service(), + + actions: { + addSubfolder(name) { + let folder = this.get('file'); + if (name) { + let p = this.get('fileManager').addSubfolder(folder, name); + p.then(() => { + this.get('store').unloadRecord(folder); + this.get('onChange')(); + }); + } + }, + + uploadFile() { + }, + + rename(newName) { + let file = this.get('file'); + if (newName) { + let p = this.get('fileManager').rename(file, newName); + let onChange = this.get('onChange'); + p.then(() => { + file.set('name', newName); + this.get('onChange')(); + }); + } + }, + + deleteFile() { + let file = this.get('file'); + let p = this.get('fileManager').deleteFile(file); + p.then(() => { + file.get('parentFolder').get('files').removeObject(file); + this.get('onChange')(); + }); + } + } +}); diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs new file mode 100644 index 000000000..24f1aece3 --- /dev/null +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -0,0 +1,19 @@ +{{#unless file.isProvider}} +

+ Rename: {{input value=newName}} + +

+

+ Delete: +

+{{/unless}} + +{{#if file.isFolder}} +

+ New folder: {{input value=newFolderName}} + +

+{{/if}} diff --git a/tests/dummy/app/components/files-tree/component.js b/tests/dummy/app/components/files-tree/component.js index c7503972a..5df74b27d 100644 --- a/tests/dummy/app/components/files-tree/component.js +++ b/tests/dummy/app/components/files-tree/component.js @@ -3,5 +3,4 @@ import layout from './template'; export default Ember.Component.extend({ layout, - fileManager: Ember.inject.service() }); diff --git a/tests/dummy/app/components/files-tree/template.hbs b/tests/dummy/app/components/files-tree/template.hbs index 99a516d67..88e685610 100644 --- a/tests/dummy/app/components/files-tree/template.hbs +++ b/tests/dummy/app/components/files-tree/template.hbs @@ -1,18 +1,19 @@ -

- - {{#if model.isFolder}} - ({{link-to 'folder details' 'file' model}}) +

+ {{#if root.isProvider}} + {{link-to root.name 'nodes.detail.files.provider' node root}} + {{else}} + {{link-to root.name 'nodes.detail.files.provider.file' + node root.provider root}} + {{/if}} + {{#if root.isFolder}}
    - {{#each model.files as |file|}} + {{#each root.files as |file|}}
  • - {{file.name}} - ({{#link-to 'file' file}}{{file.kind}} details{{/link-to}}) + {{files-tree root=file node=node}}
  • {{else}} -
  • (empty)
  • +
  • (empty folder)
  • {{/each}}
- {{else}} - ({{link-to 'file details' 'file' model}}) {{/if}} -

+
diff --git a/tests/dummy/app/controllers/nodes/detail/files/provider/file.js b/tests/dummy/app/controllers/nodes/detail/files/provider/file.js new file mode 100644 index 000000000..a76c96c98 --- /dev/null +++ b/tests/dummy/app/controllers/nodes/detail/files/provider/file.js @@ -0,0 +1,10 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + actions: { + reloadFiles() { + this.transitionToRoute('nodes.detail.files.provider', + this.get('node'), this.model.get('provider')); + } + } +}); diff --git a/tests/dummy/app/controllers/nodes/detail/files/provider/index.js b/tests/dummy/app/controllers/nodes/detail/files/provider/index.js new file mode 100644 index 000000000..084ed2031 --- /dev/null +++ b/tests/dummy/app/controllers/nodes/detail/files/provider/index.js @@ -0,0 +1,9 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + actions: { + reloadFiles() { + debugger; + } + } +}); diff --git a/tests/dummy/app/routes/nodes/detail/files.js b/tests/dummy/app/routes/nodes/detail/files.js index c8668df6f..98fe1bbf2 100644 --- a/tests/dummy/app/routes/nodes/detail/files.js +++ b/tests/dummy/app/routes/nodes/detail/files.js @@ -1,8 +1,15 @@ import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Ember.Route.extend({ - model() { - var node = this.modelFor('nodes/detail'); +export default Ember.Route.extend(AuthenticatedRouteMixin, { + model(params) { + let node = this.modelFor('nodes.detail'); return node.get('files'); }, + + setupController(controller, model) { + this._super(controller, model); + let node = this.modelFor('nodes.detail'); + controller.set('node', node); + } }); diff --git a/tests/dummy/app/routes/nodes/detail/files/provider.js b/tests/dummy/app/routes/nodes/detail/files/provider.js index 6ddd95d7c..11581be50 100644 --- a/tests/dummy/app/routes/nodes/detail/files/provider.js +++ b/tests/dummy/app/routes/nodes/detail/files/provider.js @@ -1,8 +1,9 @@ import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Ember.Route.extend({ +export default Ember.Route.extend(AuthenticatedRouteMixin, { model(params) { - var fileProviders = this.modelFor('nodes/detail/files'); + let fileProviders = this.modelFor('nodes.detail.files'); return fileProviders.findBy('provider', params.provider); }, }); diff --git a/tests/dummy/app/routes/nodes/detail/files/provider/file.js b/tests/dummy/app/routes/nodes/detail/files/provider/file.js index 868df65b7..e76a20004 100644 --- a/tests/dummy/app/routes/nodes/detail/files/provider/file.js +++ b/tests/dummy/app/routes/nodes/detail/files/provider/file.js @@ -2,48 +2,14 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; export default Ember.Route.extend(AuthenticatedRouteMixin, { - fileManager: Ember.inject.service(), - model(params) { - // TODO: verify that this file actually belongs to the parent node? + // TODO: verify this file actually belongs to the parent node? return this.store.findRecord('file', params.file_id); }, - actions: { - addSubfolder(name) { - let folder = this.modelFor(this.routeName); - if (name && folder.get('isFolder')) { - let p = this.get('fileManager').addSubfolder(folder, name); - p.then(() => { - this.store.unloadRecord(folder); - this.refresh(); - }); - } - }, - - uploadFile() { - }, - - rename(newName) { - let file = this.modelFor(this.routeName); - if (newName && newName !== file.get('name')) { - let p = this.get('fileManager').rename(file, newName); - p.then(() => { - file.set('name', newName); - this.refresh(); - }); - } - }, - - deleteFile() { - let file = this.modelFor(this.routeName); - let p = this.get('fileManager').deleteFile(file); - p.then(() => { - this.store.unloadRecord(file); - let node = this.modelFor('nodes.detail'); - this.replaceWith('nodes.detail.files.provider', - node, file.get('provider')); - }); - } + setupController(controller, model) { + this._super(controller, model); + let node = this.modelFor('nodes.detail'); + controller.set('node', node); } }); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs index c24cd6895..1ce4e8a27 100644 --- a/tests/dummy/app/templates/nodes/detail/files.hbs +++ b/tests/dummy/app/templates/nodes/detail/files.hbs @@ -1 +1,5 @@ +
+ {{link-to 'Back to node' 'nodes.detail' node class='btn btn-primary'}} +
+ {{outlet}} diff --git a/tests/dummy/app/templates/nodes/detail/files/index.hbs b/tests/dummy/app/templates/nodes/detail/files/index.hbs new file mode 100644 index 000000000..7ec44e201 --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/files/index.hbs @@ -0,0 +1,6 @@ +
+

Files

+ {{#each model as |provider|}} + {{files-tree root=provider node=provider.node}} + {{/each}} +
diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs index 3eddb05a8..307a706a9 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs @@ -1,4 +1,9 @@
+
+ {{#link-to 'nodes.detail.files.provider' node model.provider class='btn'}} + Back to {{model.provider}} + {{/link-to}} +

File detail: {{model.name}}

{{model.kind}}

{{model.provider}}

@@ -12,27 +17,14 @@

Actions

-

- Rename: {{input value=newName}} - -

-

- Delete: -

- {{#if model.isFolder}} -

- New folder: {{input value=newFolderName}} - -

+ {{file-actions file=model onChange=(action 'reloadFiles')}} -
+
+ {{#if model.isFolder}}

Files

- {{files-tree model=model}} + {{files-tree root=model node=node}} {{else}} -
+

Versions

    {{#each model.versions as |version|}} diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs new file mode 100644 index 000000000..da8a20836 --- /dev/null +++ b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs @@ -0,0 +1,13 @@ +
    +
    + {{link-to 'Back to providers' 'nodes.detail.files' + model.node class='btn'}} +
    +

    {{model.name}}

    + + {{files-tree root=model node=model.node}} + +
    + + {{file-actions file=model onChange=(action 'reloadFiles')}} +
    diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index 0172728c6..26e2608be 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -43,8 +43,7 @@

    -

    Files

    - {{#each model.files as |provider|}} - {{files-tree model=provider}} - {{/each}} +
    +

    Files

    + {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}}
From 6632b5044f6e7d8d04bf0b0290359b83d605a89d Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Tue, 17 May 2016 15:27:46 -0400 Subject: [PATCH 184/959] Add signup route --- tests/dummy/app/router.js | 1 + tests/dummy/app/routes/signup.js | 4 ++++ tests/dummy/app/templates/login.hbs | 3 +++ tests/dummy/app/templates/signup.hbs | 5 +++++ 4 files changed, 13 insertions(+) create mode 100644 tests/dummy/app/routes/signup.js create mode 100644 tests/dummy/app/templates/signup.hbs diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 216e91a03..49309d4cd 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -15,6 +15,7 @@ Router.map(function() { }); }); this.route('login'); + this.route('signup'); this.route('institutions', function() { this.route('detail', { path: '/:institution_id' diff --git a/tests/dummy/app/routes/signup.js b/tests/dummy/app/routes/signup.js new file mode 100644 index 000000000..26d9f3124 --- /dev/null +++ b/tests/dummy/app/routes/signup.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ +}); diff --git a/tests/dummy/app/templates/login.hbs b/tests/dummy/app/templates/login.hbs index 33f7480f5..54526a547 100644 --- a/tests/dummy/app/templates/login.hbs +++ b/tests/dummy/app/templates/login.hbs @@ -1,2 +1,5 @@

Login to begin

+ +

Sign Up

+{{link-to 'Sign Up' 'signup' class="btn btn-default"}} diff --git a/tests/dummy/app/templates/signup.hbs b/tests/dummy/app/templates/signup.hbs new file mode 100644 index 000000000..1cddb26cc --- /dev/null +++ b/tests/dummy/app/templates/signup.hbs @@ -0,0 +1,5 @@ +
+
+ {{#sign-up}}{{/sign-up}} +
+
\ No newline at end of file From c240bdc270288443b826f4cbe188d643eff29d9e Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Tue, 17 May 2016 15:56:31 -0400 Subject: [PATCH 185/959] Uploading files [skip ci] --- addon/serializers/file-provider.js | 4 ++-- addon/services/file-manager.js | 1 + tests/dummy/app/components/file-actions/component.js | 10 +++++++++- tests/dummy/app/components/file-actions/template.hbs | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/addon/serializers/file-provider.js b/addon/serializers/file-provider.js index 11d1cfeed..eef2a2728 100644 --- a/addon/serializers/file-provider.js +++ b/addon/serializers/file-provider.js @@ -1,6 +1,6 @@ -import JSONAPISerializer from 'ember-data/serializers/json-api'; +import ApplicationSerializer from 'ember-osf/serializers/application'; -export default JSONAPISerializer.extend({ +export default ApplicationSerializer.extend({ modelNameFromPayloadKey() { return 'file-provider'; } diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index 2cfc26bbb..4db2f930b 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -103,6 +103,7 @@ export default Ember.Service.extend({ Ember.$.ajax(url, { method, data, + processData: false, headers: { Authorization: `Bearer ${accessToken}` }, diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index 145e0e652..a8e726e91 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -18,7 +18,15 @@ export default Ember.Component.extend({ } }, - uploadFile() { + uploadFile(evt) { + let newFile = evt.target.files[0]; + let folder = this.get('file'); + if (newFile) { + let fm = this.get('fileManager'); + fm.uploadFile(folder, newFile.name, newFile).then(() => { + this.get('onChange')(); + }); + } }, rename(newName) { diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index 24f1aece3..259081e8a 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -16,4 +16,7 @@

+

+ Upload file: {{input type='file' change=(action 'uploadFile')}} +

{{/if}} From fd49cdfef5bd1c564c68337c08a97ee54b543a99 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Tue, 17 May 2016 15:56:44 -0400 Subject: [PATCH 186/959] WIP relationship dirty tracking --- addon/adapters/node.js | 28 ++++++++++++++++++++++------ addon/mixins/osf-login-controller.js | 2 +- addon/mixins/osf-model.js | 17 ++++++++++++++++- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 1dc9ec289..5ca94e984 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -1,13 +1,29 @@ +import Ember from 'ember'; + import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ - buildURL(_, __, ___, requestType) { - // Embed contributors - var base = this._super(...arguments); - if (['createRecord', 'updateRecord', 'deleteRecord'].indexOf(requestType) === -1) { - return `${base}?embed=contributors`; + buildURL(_, __, snapshot, requestType) { + if (requestType === 'updateRecord' && !snapshot.record.changedAttributes().length) { + var dirtyRelationships = snapshot.record.get('dirtyRelationships'); + var urls = Object.keys(dirtyRelationships) + .filter((rel) => Ember.get(dirtyRelationships, rel)) + .map((rel) => { + var links = snapshot.record.get( + `links.${Ember.String.underscore(rel)}.links` + ); + return Ember.get(links, 'self.href') || links.related.href; + }); + // TODO fixme + return urls[0]; } else { - return base; + // Embed contributors + var base = this._super(...arguments); + if (['createRecord', 'updateRecord', 'deleteRecord'].indexOf(requestType) === -1) { + return `${base}?embed=contributors`; + } else { + return base; + } } } }); diff --git a/addon/mixins/osf-login-controller.js b/addon/mixins/osf-login-controller.js index 8d5545aea..b38beccbe 100644 --- a/addon/mixins/osf-login-controller.js +++ b/addon/mixins/osf-login-controller.js @@ -6,7 +6,7 @@ export default Ember.Mixin.create({ session: Ember.inject.service(), actions: { login() { - window.location = `${config.OSF.authUrl}?response_type=token&scope=${config.OSF.scope}&client_id=${config.OSF.clientId}&redirect_uri=${encodeURI(window.location)}`; + window.location = `${config.OSF.authUrl}?response_type=token&scope=${config.OSF.scope}&client_id=${config.OSF.clientId}&redirect_uri=${encodeURI(window.location)}/`; } } }); diff --git a/addon/mixins/osf-model.js b/addon/mixins/osf-model.js index a2b7fbd2f..92eed5485 100644 --- a/addon/mixins/osf-model.js +++ b/addon/mixins/osf-model.js @@ -7,5 +7,20 @@ import DS from 'ember-data'; export default Ember.Mixin.create({ links: DS.attr('links'), - embeds: DS.attr('embed') + embeds: DS.attr('embed'), + + relationshipLinks: DS.attr('links'), + dirtyRelationships: {}, + onLoad: Ember.on('ready', function() { + this.eachRelationship((rel) => { + let update = function() { + let key = `dirtyRelationships.${rel}`; + this.set(key, !Ember.isEmpty(this.get(key))); + }.bind(this); + + this.get(rel).then(() => { + this.addObserver(rel, update); + }); + }); + }) }); From ec5efbed116d929fba973b013d91a79c61a05def Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Tue, 17 May 2016 16:19:05 -0400 Subject: [PATCH 187/959] Updating file contents [skip ci] --- addon/services/file-manager.js | 4 ++++ tests/dummy/app/components/file-actions/component.js | 10 ++++++++++ tests/dummy/app/components/file-actions/template.hbs | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index 4db2f930b..54ea9c852 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -4,6 +4,10 @@ export default Ember.Service.extend({ session: Ember.inject.service(), store: Ember.inject.service(), + // TODO: After each waterbutler action, either update the Ember + // store based on the returned WB entity, or force a refresh of + // file info through the OSF. Or maybe both? + // File actions getContents(file) { var url = file.get('links').download; diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index a8e726e91..f370d4183 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -7,6 +7,16 @@ export default Ember.Component.extend({ store: Ember.inject.service(), actions: { + updateContents(evt) { + let contents = evt.target.files[0]; + let file = this.get('file'); + let fm = this.get('fileManager'); + + fm.updateContents(file, contents).then(() => { + this.get('onChange')(); + }); + }, + addSubfolder(name) { let folder = this.get('file'); if (name) { diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index 259081e8a..c5d22f3c9 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -17,6 +17,13 @@ Add folder

- Upload file: {{input type='file' change=(action 'uploadFile')}} + Upload file: + {{input type='file' change=(action 'uploadFile')}}

+{{else}} +

+ Update file contents: + {{input type='file' change=(action 'updateContents')}} +

+ {{/if}} From 2862212df1d513588fc7af9b51c5ed193bf1428c Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Tue, 17 May 2016 16:48:38 -0400 Subject: [PATCH 188/959] ayy lmao --- addon/adapters/node.js | 1 + tests/dummy/app/routes/nodes/detail.js | 12 +++++++++++- tests/dummy/app/templates/nodes/detail.hbs | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 1dc9ec289..5f12fc896 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -3,6 +3,7 @@ import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ buildURL(_, __, ___, requestType) { // Embed contributors + debugger; var base = this._super(...arguments); if (['createRecord', 'updateRecord', 'deleteRecord'].indexOf(requestType) === -1) { return `${base}?embed=contributors`; diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index e1ea35f24..3a5b31679 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -21,7 +21,17 @@ export default Ember.Route.extend({ } else { console.log('You do not have permissions to edit this node'); } - } + }, + affiliateNode(instId){ + var self = this; + self.store.findRecord('institution', instId).then( + function(inst){ + var node = self.modelFor(self.routeName); + node.get('affiliatedInstitutions').pushObject(inst); + node.save(); + } + ); + }, } }); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index bdee11b0d..62a988595 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -42,6 +42,11 @@ {{/each}}

+

+ + {{input type="text" value=instId placeholder="institution's id"}} +

+

Files

{{#each model.files as |provider|}} From 4a03740bf037b4ac779e0618968652a81892eb34 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 17 May 2016 16:56:02 -0400 Subject: [PATCH 189/959] Configurable token/cookie authorizer (currently doesn't work/ page doesn't load) [ci skip] --- addon/adapters/application.js | 2 +- addon/authorizers/osf-cookie.js | 8 ++++++++ app/authenticators/osf-cookie.js | 1 + app/authorizers/osf-cookie.js | 1 + index.js | 23 ++++++++++++++++++++++- tests/dummy/app/router.js | 4 ++-- tests/dummy/app/routes/cookielogin.js | 4 ++-- tests/dummy/app/templates/cookielogin.hbs | 3 +++ 8 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 addon/authorizers/osf-cookie.js create mode 100644 app/authenticators/osf-cookie.js create mode 100644 app/authorizers/osf-cookie.js diff --git a/addon/adapters/application.js b/addon/adapters/application.js index cff7dd94b..bb1a47348 100644 --- a/addon/adapters/application.js +++ b/addon/adapters/application.js @@ -5,7 +5,7 @@ import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; import config from 'ember-get-config'; export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { - authorizer: 'authorizer:osf-token', + authorizer: config['ember-simple-auth'].authorizer, host: config.OSF.apiUrl, namespace: config.OSF.apiNamespace, pathForType: Ember.String.pluralize, diff --git a/addon/authorizers/osf-cookie.js b/addon/authorizers/osf-cookie.js new file mode 100644 index 000000000..b8a53fcf8 --- /dev/null +++ b/addon/authorizers/osf-cookie.js @@ -0,0 +1,8 @@ +import Base from 'ember-simple-auth/authorizers/base'; + +export default Base.extend({ + authorize(/*data, block*/) { + // xhr object should be accessible from outer closure + xhr.withCredentials = true; + } +}); diff --git a/app/authenticators/osf-cookie.js b/app/authenticators/osf-cookie.js new file mode 100644 index 000000000..bab24e9bb --- /dev/null +++ b/app/authenticators/osf-cookie.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/authenticators/osf-cookie'; diff --git a/app/authorizers/osf-cookie.js b/app/authorizers/osf-cookie.js new file mode 100644 index 000000000..20b167475 --- /dev/null +++ b/app/authorizers/osf-cookie.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/authorizers/osf-cookie'; diff --git a/index.js b/index.js index c28960264..3f16267e4 100644 --- a/index.js +++ b/index.js @@ -55,5 +55,26 @@ module.exports = { ENV['ember-simple-auth'] = { authorizer: 'authorizer:osf-token' }; - } + + + let AUTHORIZER = process.env.AUTHORIZER || 'token'; + switch (AUTHORIZER) { + case 'cookie': + ENV['ember-simple-auth'] = { + authorizer: 'authorizer:osf-cookie', + authenticationRoute: 'cookielogin' + }; + console.log('configured cookie auth'); + break; + case 'token': + default: + // TODO: set settings in setting-ish fashion + // TODO: Don't set default route here, though useful for testing with dummy app + console.log('configured token auth'); + + } + } + + + }; diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 39322279a..2e042f1b4 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -9,12 +9,13 @@ Router.map(function() { this.route('index', { path: '/' }); + //this.route('login'); + this.route('cookielogin'); this.route('nodes', function() { this.route('detail', { path: '/:node_id' }); }); - this.route('login'); this.route('institutions', function() { this.route('detail', { path: '/:institution_id' @@ -33,7 +34,6 @@ Router.map(function() { this.route('file', { path: '/file/:file_id' }); - this.route('cookielogin'); }); export default Router; diff --git a/tests/dummy/app/routes/cookielogin.js b/tests/dummy/app/routes/cookielogin.js index 640a5bac0..f9681cdff 100644 --- a/tests/dummy/app/routes/cookielogin.js +++ b/tests/dummy/app/routes/cookielogin.js @@ -1,5 +1,5 @@ import Ember from 'ember'; +import OsfCookieLoginRouteMixin from 'ember-osf/mixins/osf-cookie-login-route'; - -export default Ember.Route.extend({ +export default Ember.Route.extend(OsfCookieLoginRouteMixin, { }); diff --git a/tests/dummy/app/templates/cookielogin.hbs b/tests/dummy/app/templates/cookielogin.hbs index 820ec351e..0d8ee0bc6 100644 --- a/tests/dummy/app/templates/cookielogin.hbs +++ b/tests/dummy/app/templates/cookielogin.hbs @@ -1 +1,4 @@ {{login-form loginSubmit=(action 'loginHandler')}} + + +Ticket attached: {{ticket}} \ No newline at end of file From aaa67fa025f95a08730fd9600a6181cd5f195c15 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Tue, 17 May 2016 16:58:59 -0400 Subject: [PATCH 190/959] Fix css & add signup css --- bower.json | 3 +- package.json | 16 +++++++- tests/dummy/app/components/sign-up/style.css | 40 ++++++++++++++++++++ tests/dummy/app/styles/app.css | 0 tests/dummy/app/styles/app.scss | 2 + 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/dummy/app/components/sign-up/style.css delete mode 100644 tests/dummy/app/styles/app.css diff --git a/bower.json b/bower.json index c435c94aa..d5593d67d 100644 --- a/bower.json +++ b/bower.json @@ -7,7 +7,8 @@ "ember-qunit-notifications": "0.1.0", "Faker": "~3.0.0", "pretender": "~0.10.1", - "lodash": "~3.7.0" + "lodash": "~3.7.0", + "bootstrap-sass": "^3.3.6" }, "devDependencies": { "bootstrap": "^3.3.6" diff --git a/package.json b/package.json index 0bb721a25..cf054774c 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build": "ember build", "start": "ember server", "test": "ember test", - "check-style": "./node_modules/jscs/bin/jscs ." + "check-style": "./node_modules/jscs/bin/jscs ." }, "repository": "", "engines": { @@ -25,6 +25,7 @@ "ember-ajax": "0.7.1", "ember-cli": "^2.4.3", "ember-cli-app-version": "^1.0.0", + "ember-cli-bootstrap-sassy": "0.5.3", "ember-cli-dependency-checker": "^1.2.0", "ember-cli-htmlbars": "^1.0.1", "ember-cli-htmlbars-inline-precompile": "^0.3.1", @@ -35,6 +36,7 @@ "ember-cli-sass": "5.3.1", "ember-cli-sri": "^2.0.0", "ember-cli-uglify": "^1.2.0", + "ember-component-css": "0.1.9", "ember-data": "^2.3.0", "ember-disable-prototype-extensions": "^1.0.0", "ember-disable-proxy-controllers": "^1.0.1", @@ -67,7 +69,17 @@ }, "jscsConfig": { "preset": "airbnb", - "excludeFiles": ["bower_components", "dist", "tmp", "vendor", "app/locales", "tests/unit", "tests/integration", "tests/helpers", "tests/dummy/app/mirage"], + "excludeFiles": [ + "bower_components", + "dist", + "tmp", + "vendor", + "app/locales", + "tests/unit", + "tests/integration", + "tests/helpers", + "tests/dummy/app/mirage" + ], "requireSpacesInAnonymousFunctionExpression": false, "requireTrailingComma": false, "disallowTrailingComma": false, diff --git a/tests/dummy/app/components/sign-up/style.css b/tests/dummy/app/components/sign-up/style.css new file mode 100644 index 000000000..989eadcc6 --- /dev/null +++ b/tests/dummy/app/components/sign-up/style.css @@ -0,0 +1,40 @@ +.toggle-box { + height: 320px; + border: 1px solid #EEE; +} + +.toggle-box-left { + border-right: none; +} +.toggle-box-right { + +} + +.toggle-box-active { + z-index: 1; +} +.toggle-box-active.toggle-box-left { + box-shadow: 3px 0px 6px -2px #AAA; + border-left: 3px solid #5CB85C; +} +.toggle-box-active.toggle-box-right { + box-shadow: -3px 0px 6px -2px #AAA; + border-right: 3px solid #5CB85C; +} + +.toggle-box-muted { + background-color: #F5F5F5; + color: #ccc; +} +.toggle-box-muted .btn.btn-default { + color: #ccc; + border-color: #eee; +} +.toggle-box-muted input { + color: #ccc; + border-color: #eee; +} +.toggle-box-muted .btn-success { + background-color: #CCC; + border-color: #BBB; +} diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/dummy/app/styles/app.scss b/tests/dummy/app/styles/app.scss index e69de29bb..dfb441828 100644 --- a/tests/dummy/app/styles/app.scss +++ b/tests/dummy/app/styles/app.scss @@ -0,0 +1,2 @@ +@import "bootstrap"; +@import "pod-styles"; From 1c2dce7ce134cf6ae2e17e9192de6328ee3044a2 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Tue, 17 May 2016 17:06:24 -0400 Subject: [PATCH 191/959] File download and random changes [skip ci] --- addon/services/file-manager.js | 4 +- .../app/components/file-actions/component.js | 6 ++ .../app/components/file-actions/template.hbs | 91 +++++++++++++------ .../app/components/files-tree/template.hbs | 12 ++- .../nodes/detail/files/provider/index.js | 2 +- .../nodes/detail/files/provider/file.hbs | 3 +- .../nodes/detail/files/provider/index.hbs | 1 + 7 files changed, 81 insertions(+), 38 deletions(-) diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index 54ea9c852..56a25462f 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -5,8 +5,8 @@ export default Ember.Service.extend({ store: Ember.inject.service(), // TODO: After each waterbutler action, either update the Ember - // store based on the returned WB entity, or force a refresh of - // file info through the OSF. Or maybe both? + // store based on the returned WB entity (when possible), or force a + // refresh of file info through the OSF. Or maybe both? // File actions getContents(file) { diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index f370d4183..e50c7dd50 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -7,6 +7,12 @@ export default Ember.Component.extend({ store: Ember.inject.service(), actions: { + download() { + let file = this.get('file'); + let url = file.get('links').download; + window.open(url); + }, + updateContents(evt) { let contents = evt.target.files[0]; let file = this.get('file'); diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index c5d22f3c9..288b568f6 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -1,29 +1,62 @@ -{{#unless file.isProvider}} -

- Rename: {{input value=newName}} - -

-

- Delete: -

-{{/unless}} - -{{#if file.isFolder}} -

- New folder: {{input value=newFolderName}} - -

-

- Upload file: - {{input type='file' change=(action 'uploadFile')}} -

-{{else}} -

- Update file contents: - {{input type='file' change=(action 'updateContents')}} -

- -{{/if}} + + {{#if file.isFolder}} + + + + + + + + + + {{#unless file.isProvider}} + + + + + + + + + + {{/unless}} + {{else}} + + + + + + + + {{/if}} +
+ New folder: + + {{input value=newFolderName}} + + +
+ Upload file: + + {{input type='file' change=(action 'uploadFile')}} +
+ Rename: + + {{input value=newName}} + + +
+ Delete: + + +
+ +
+ Update file contents: + + {{input type='file' change=(action 'updateContents')}} +
diff --git a/tests/dummy/app/components/files-tree/template.hbs b/tests/dummy/app/components/files-tree/template.hbs index 88e685610..def3b6862 100644 --- a/tests/dummy/app/components/files-tree/template.hbs +++ b/tests/dummy/app/components/files-tree/template.hbs @@ -1,9 +1,13 @@
- {{#if root.isProvider}} - {{link-to root.name 'nodes.detail.files.provider' node root}} + {{#if onClickFile}} + {{root.name}} {{else}} - {{link-to root.name 'nodes.detail.files.provider.file' - node root.provider root}} + {{#if root.isProvider}} + {{link-to root.name 'nodes.detail.files.provider' node root}} + {{else}} + {{link-to root.name 'nodes.detail.files.provider.file' + node root.provider root}} + {{/if}} {{/if}} {{#if root.isFolder}}
    diff --git a/tests/dummy/app/controllers/nodes/detail/files/provider/index.js b/tests/dummy/app/controllers/nodes/detail/files/provider/index.js index 084ed2031..830de37f4 100644 --- a/tests/dummy/app/controllers/nodes/detail/files/provider/index.js +++ b/tests/dummy/app/controllers/nodes/detail/files/provider/index.js @@ -3,7 +3,7 @@ import Ember from 'ember'; export default Ember.Controller.extend({ actions: { reloadFiles() { - debugger; + // TODO? } } }); diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs index 307a706a9..b94d58fbe 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs @@ -4,8 +4,7 @@ Back to {{model.provider}} {{/link-to}}
-

File detail: {{model.name}}

-

{{model.kind}}

+

{{model.kind}} detail: {{model.name}}

{{model.provider}}

{{model.path}}

{{model.materializedPath}}

diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs index da8a20836..8a85b8b86 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs @@ -9,5 +9,6 @@
+

Actions

{{file-actions file=model onChange=(action 'reloadFiles')}}
From 44ed16661349be446476574eaa1114c84cc58952 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Tue, 17 May 2016 17:18:33 -0400 Subject: [PATCH 192/959] Show rename/delete for files, too [skip ci] --- .../app/components/file-actions/template.hbs | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index 288b568f6..d978293b8 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -1,4 +1,27 @@ + {{#unless file.isProvider}} + + + + + + + + + + {{/unless}} {{#if file.isFolder}} - {{#unless file.isProvider}} - - - - - - - - - - {{/unless}} {{else}} + + + + + {{/unless}} {{#if file.isFolder}} diff --git a/tests/dummy/app/components/file-tree/template.hbs b/tests/dummy/app/components/file-tree/template.hbs index def3b6862..9330ce1a3 100644 --- a/tests/dummy/app/components/file-tree/template.hbs +++ b/tests/dummy/app/components/file-tree/template.hbs @@ -1,4 +1,4 @@ -
+
{{#if onClickFile}} {{root.name}} {{else}} @@ -13,7 +13,7 @@
    {{#each root.files as |file|}}
  • - {{files-tree root=file node=node}} + {{file-tree root=file node=node}}
  • {{else}}
  • (empty folder)
  • diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs index 66fd135f8..ca052c4f7 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs @@ -5,6 +5,7 @@ {{/link-to}}

{{model.kind}} detail: {{model.name}}

+

{{model.id}}

{{model.provider}}

{{model.path}}

{{model.materializedPath}}

diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs index 5357f5c88..df20475ae 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs @@ -4,7 +4,11 @@ model.node class='btn'}}

{{model.name}}

+

{{model.id}}

+

{{model.provider}}

+

{{model.path}}

+

Files

{{file-tree root=model node=model.node}}
From 0094a1e36c168d27b01402c97ec4019779d3fc06 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Wed, 18 May 2016 09:53:30 -0400 Subject: [PATCH 196/959] Add login-form component --- .../app/components/login-form/component.js | 6 +++ .../dummy/app/components/login-form/style.css | 40 ++++++++++++++++ .../app/components/login-form/template.hbs | 46 +++++++++++++++++++ tests/dummy/app/templates/signup.hbs | 3 ++ 4 files changed, 95 insertions(+) create mode 100644 tests/dummy/app/components/login-form/component.js create mode 100644 tests/dummy/app/components/login-form/style.css create mode 100644 tests/dummy/app/components/login-form/template.hbs diff --git a/tests/dummy/app/components/login-form/component.js b/tests/dummy/app/components/login-form/component.js new file mode 100644 index 000000000..8ef0d629f --- /dev/null +++ b/tests/dummy/app/components/login-form/component.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; +import layout from './template'; + +export default Ember.Component.extend({ + layout +}); diff --git a/tests/dummy/app/components/login-form/style.css b/tests/dummy/app/components/login-form/style.css new file mode 100644 index 000000000..989eadcc6 --- /dev/null +++ b/tests/dummy/app/components/login-form/style.css @@ -0,0 +1,40 @@ +.toggle-box { + height: 320px; + border: 1px solid #EEE; +} + +.toggle-box-left { + border-right: none; +} +.toggle-box-right { + +} + +.toggle-box-active { + z-index: 1; +} +.toggle-box-active.toggle-box-left { + box-shadow: 3px 0px 6px -2px #AAA; + border-left: 3px solid #5CB85C; +} +.toggle-box-active.toggle-box-right { + box-shadow: -3px 0px 6px -2px #AAA; + border-right: 3px solid #5CB85C; +} + +.toggle-box-muted { + background-color: #F5F5F5; + color: #ccc; +} +.toggle-box-muted .btn.btn-default { + color: #ccc; + border-color: #eee; +} +.toggle-box-muted input { + color: #ccc; + border-color: #eee; +} +.toggle-box-muted .btn-success { + background-color: #CCC; + border-color: #BBB; +} diff --git a/tests/dummy/app/components/login-form/template.hbs b/tests/dummy/app/components/login-form/template.hbs new file mode 100644 index 000000000..a5bb6607c --- /dev/null +++ b/tests/dummy/app/components/login-form/template.hbs @@ -0,0 +1,46 @@ + \ No newline at end of file diff --git a/tests/dummy/app/templates/signup.hbs b/tests/dummy/app/templates/signup.hbs index 1cddb26cc..2440f36a7 100644 --- a/tests/dummy/app/templates/signup.hbs +++ b/tests/dummy/app/templates/signup.hbs @@ -1,4 +1,7 @@
+
+ {{#login-form}}{{/login-form}} +
{{#sign-up}}{{/sign-up}}
From 40e06a1c2e7bc4ec7103783476fb168e9b71ba9c Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 18 May 2016 10:47:02 -0400 Subject: [PATCH 197/959] Add ember-component-css and ember-cli-boostrap-sassy --- bower.json | 3 ++- ember-cli-build.js | 20 -------------------- index.js | 4 ++++ package.json | 20 ++++++++++++++++---- tests/dummy/app/styles/app.css | 0 tests/dummy/app/styles/app.scss | 2 ++ 6 files changed, 24 insertions(+), 25 deletions(-) delete mode 100644 tests/dummy/app/styles/app.css diff --git a/bower.json b/bower.json index c435c94aa..d5593d67d 100644 --- a/bower.json +++ b/bower.json @@ -7,7 +7,8 @@ "ember-qunit-notifications": "0.1.0", "Faker": "~3.0.0", "pretender": "~0.10.1", - "lodash": "~3.7.0" + "lodash": "~3.7.0", + "bootstrap-sass": "^3.3.6" }, "devDependencies": { "bootstrap": "^3.3.6" diff --git a/ember-cli-build.js b/ember-cli-build.js index 77eb87914..341c87475 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -4,25 +4,5 @@ var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { var app = new EmberAddon(defaults, {}); - - app.import('bower_components/bootstrap/dist/css/bootstrap.min.css'); - app.import('bower_components/bootstrap/dist/css/bootstrap-theme.min.css'); - app.import('bower_components/bootstrap/dist/js/bootstrap.min.js'); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff', { - destDir: 'fonts' - }); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot', { - destDir: 'fonts' - }); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg', { - destDir: 'fonts' - }); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf', { - destDir: 'fonts' - }); - app.import('bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2', { - destDir: 'fonts' - }); - return app.toTree(); }; diff --git a/index.js b/index.js index c28960264..83fa00fc7 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ 'use strict'; var path = require('path'); var config = require('config'); +// var Funnel = require('broccoli-funnel'); module.exports = { name: 'ember-osf', @@ -55,5 +56,8 @@ module.exports = { ENV['ember-simple-auth'] = { authorizer: 'authorizer:osf-token' }; + }, + treeForStyles: function(/*tree*/) { + // TODO expose ember-osf styles } }; diff --git a/package.json b/package.json index 0bb721a25..653a3592a 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build": "ember build", "start": "ember server", "test": "ember test", - "check-style": "./node_modules/jscs/bin/jscs ." + "check-style": "./node_modules/jscs/bin/jscs ." }, "repository": "", "engines": { @@ -25,9 +25,8 @@ "ember-ajax": "0.7.1", "ember-cli": "^2.4.3", "ember-cli-app-version": "^1.0.0", + "ember-cli-bootstrap-sassy": "0.5.3", "ember-cli-dependency-checker": "^1.2.0", - "ember-cli-htmlbars": "^1.0.1", - "ember-cli-htmlbars-inline-precompile": "^0.3.1", "ember-cli-inject-live-reload": "^1.3.1", "ember-cli-mirage": "0.1.13", "ember-cli-qunit": "^1.2.1", @@ -35,6 +34,7 @@ "ember-cli-sass": "5.3.1", "ember-cli-sri": "^2.0.0", "ember-cli-uglify": "^1.2.0", + "ember-component-css": "0.1.9", "ember-data": "^2.3.0", "ember-disable-prototype-extensions": "^1.0.0", "ember-disable-proxy-controllers": "^1.0.1", @@ -55,6 +55,8 @@ "dependencies": { "config": "^1.20.1", "ember-cli-babel": "^5.1.5", + "ember-cli-htmlbars": "^1.0.1", + "ember-cli-htmlbars-inline-precompile": "^0.3.1", "ember-cli-moment-shim": "1.1.0", "ember-cli-node-assets": "^0.1.3", "ember-get-config": "0.0.2", @@ -67,7 +69,17 @@ }, "jscsConfig": { "preset": "airbnb", - "excludeFiles": ["bower_components", "dist", "tmp", "vendor", "app/locales", "tests/unit", "tests/integration", "tests/helpers", "tests/dummy/app/mirage"], + "excludeFiles": [ + "bower_components", + "dist", + "tmp", + "vendor", + "app/locales", + "tests/unit", + "tests/integration", + "tests/helpers", + "tests/dummy/app/mirage" + ], "requireSpacesInAnonymousFunctionExpression": false, "requireTrailingComma": false, "disallowTrailingComma": false, diff --git a/tests/dummy/app/styles/app.css b/tests/dummy/app/styles/app.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/dummy/app/styles/app.scss b/tests/dummy/app/styles/app.scss index e69de29bb..20b4c4edb 100644 --- a/tests/dummy/app/styles/app.scss +++ b/tests/dummy/app/styles/app.scss @@ -0,0 +1,2 @@ +@import "bootstrap"; +@import "pod-styles"; \ No newline at end of file From 4e8b349dd7d288a6e312e2524461d7ad7869fcc2 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 18 May 2016 11:32:26 -0400 Subject: [PATCH 198/959] Fix index.js formatting --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 83fa00fc7..13538ab5e 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,6 @@ module.exports = { }; }, treeForStyles: function(/*tree*/) { - // TODO expose ember-osf styles + // TODO expose ember-osf styles } }; From bc4df34f5db6071f2739152f4662c3f3bc7cf1a8 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Wed, 18 May 2016 12:15:33 -0400 Subject: [PATCH 199/959] Move dummy app specific config to dummy app [ci skip] --- index.js | 20 +------------------- tests/dummy/app/router.js | 2 +- tests/dummy/config/environment.js | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index 3f16267e4..63094e6da 100644 --- a/index.js +++ b/index.js @@ -55,25 +55,7 @@ module.exports = { ENV['ember-simple-auth'] = { authorizer: 'authorizer:osf-token' }; - - - let AUTHORIZER = process.env.AUTHORIZER || 'token'; - switch (AUTHORIZER) { - case 'cookie': - ENV['ember-simple-auth'] = { - authorizer: 'authorizer:osf-cookie', - authenticationRoute: 'cookielogin' - }; - console.log('configured cookie auth'); - break; - case 'token': - default: - // TODO: set settings in setting-ish fashion - // TODO: Don't set default route here, though useful for testing with dummy app - console.log('configured token auth'); - - } - } + } diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index d1a214d8b..4fb50ab2b 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -9,7 +9,7 @@ Router.map(function() { this.route('index', { path: '/' }); - //this.route('login'); + this.route('login'); this.route('cookielogin'); this.route('nodes', function() { this.route('detail', { diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index ee8ecc20e..a15132b2b 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -2,6 +2,16 @@ module.exports = function(environment) { + // Allow the dummy app to support either token or cookie auth as needed. (default to tokens) + var AUTHORIZER = process.env.AUTHORIZER || 'token'; + var authConfig = {}; + if (AUTHORIZER === 'cookie') { + authConfig = { + authorizer: 'authorizer:osf-cookie', + authenticationRoute: 'cookielogin' + }; + } + var ENV = { modulePrefix: 'dummy', environment: environment, @@ -17,10 +27,8 @@ module.exports = function(environment) { // Here you can pass flags/options to your application instance // when it is created }, - 'ember-simple-auth': { - authenticationRoute: 'login', - routeAfterAuthentication: 'index' - }, + + 'ember-simple-auth': authConfig, // TODO: Does this override any default behaviors? 'ember-cli-mirage': { enabled: false } From 312ee9bd262371fbff15858ff6d44df99777a611 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Wed, 18 May 2016 13:59:57 -0400 Subject: [PATCH 200/959] Save an experiment that partly works; redirects need work Hard-coded urls = ick [ci skip] --- addon/adapters/osf-adapter.js | 2 ++ addon/authenticators/osf-cookie.js | 9 +++++++-- addon/authorizers/osf-cookie.js | 4 +++- addon/templates/components/login-form.hbs | 21 ++++++++++++++++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index 6265ba335..45adfde4e 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -18,6 +18,8 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { if (url.lastIndexOf('/') !== 0) { url += '/'; } + + console.log('authorizer', config['ember-simple-auth'].authorizer); return url; } }); diff --git a/addon/authenticators/osf-cookie.js b/addon/authenticators/osf-cookie.js index 6132bbd5c..600fdb09b 100644 --- a/addon/authenticators/osf-cookie.js +++ b/addon/authenticators/osf-cookie.js @@ -23,8 +23,13 @@ export default Base.extend({ }, authenticate(code) { - // For now, authentication consists of sending the user to OSF - return Ember.$.get({url: config.OSF.url + 'ticket=' + code}) + // Authentication procedure: hit an OSF endpoint with a URL parameter "ticket". If backend validates the ticket, the response should set a cookie + return Ember.$.get({ + url: config.OSF.url + 'login/?ticket=' + code, + xhrFields: { + withCredentials: true + } + }) .then(()=> console.log(...arguments)); // TODO: rv? } diff --git a/addon/authorizers/osf-cookie.js b/addon/authorizers/osf-cookie.js index b8a53fcf8..f030a4afe 100644 --- a/addon/authorizers/osf-cookie.js +++ b/addon/authorizers/osf-cookie.js @@ -3,6 +3,8 @@ import Base from 'ember-simple-auth/authorizers/base'; export default Base.extend({ authorize(/*data, block*/) { // xhr object should be accessible from outer closure - xhr.withCredentials = true; + // https://github.com/simplabs/ember-simple-auth/blob/bed56395e8ce0e376e28b6ea9a62a4e26585d875/addon/mixins/data-adapter-mixin.js + console.log('confirm that xhr is available through closure', xhr); + //xhr.withCredentials = true; } }); diff --git a/addon/templates/components/login-form.hbs b/addon/templates/components/login-form.hbs index b6975b2b8..c93a419ea 100644 --- a/addon/templates/components/login-form.hbs +++ b/addon/templates/components/login-form.hbs @@ -1,9 +1,24 @@ {{!-- app/templates/login.hbs --}} -
+{{!-- TODO: Deal with hardcoded urls, eg exposing property through the controller (alias? one way binding?) --}} + +
+    Login flow:
+      1. This form sends to CAS
+      2. Then CAS redirects to this app's cookielogin url, so the ember authorizer can immediately pick off the ticket
+      3. The ember authorizer then sends an ajax request to the OSF so a cookie can be set
+
+    Tricky bit: the ember app and the OSF must run on the same port, so that the authorizer request doesn't trigger a CORS error when hitting the OSF
+    This is problematic, because we need to serve the ember app (for redirect from CAS) at ~same time OSF is running to respond to the ajax call
+
+    These are two separate servers (unless we build and dump into an OSF static folder somewhere)
+
+    staging url: action="https://staging-accounts.osf.io/login?service=http://localhost:4200/cookielogin/&auto=true"
+    
+ - {{input id='identification' placeholder='Enter Login' value=identification}} + {{input id='username' name='username' placeholder='Enter Login' value=identification}} - {{input id='password' placeholder='Enter Password' type='password' value=password}} + {{input id='password' name='password' placeholder='Enter Password' type='password' value=password}} {{#if errorMessage}}

{{errorMessage}}

From 855345abfd273e2d86193bd80b7dd4ebc76a34f4 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Wed, 18 May 2016 12:51:25 -0400 Subject: [PATCH 201/959] Fix indentation error --- tests/dummy/app/components/login-form/component.js | 2 +- tests/dummy/app/components/sign-up/component.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/dummy/app/components/login-form/component.js b/tests/dummy/app/components/login-form/component.js index 8ef0d629f..44bf16cc0 100644 --- a/tests/dummy/app/components/login-form/component.js +++ b/tests/dummy/app/components/login-form/component.js @@ -2,5 +2,5 @@ import Ember from 'ember'; import layout from './template'; export default Ember.Component.extend({ - layout + layout }); diff --git a/tests/dummy/app/components/sign-up/component.js b/tests/dummy/app/components/sign-up/component.js index 8ef0d629f..44bf16cc0 100644 --- a/tests/dummy/app/components/sign-up/component.js +++ b/tests/dummy/app/components/sign-up/component.js @@ -2,5 +2,5 @@ import Ember from 'ember'; import layout from './template'; export default Ember.Component.extend({ - layout + layout }); From 94fe9871f3514837fb6bde22db95308c500e7f9e Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Wed, 18 May 2016 14:58:34 -0400 Subject: [PATCH 202/959] Add file version component --- tests/dummy/app/components/file-version/component.js | 6 ++++++ tests/dummy/app/components/file-version/template.hbs | 6 ++++++ tests/dummy/app/templates/file.hbs | 6 +----- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 tests/dummy/app/components/file-version/component.js create mode 100644 tests/dummy/app/components/file-version/template.hbs diff --git a/tests/dummy/app/components/file-version/component.js b/tests/dummy/app/components/file-version/component.js new file mode 100644 index 000000000..44bf16cc0 --- /dev/null +++ b/tests/dummy/app/components/file-version/component.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; +import layout from './template'; + +export default Ember.Component.extend({ + layout +}); diff --git a/tests/dummy/app/components/file-version/template.hbs b/tests/dummy/app/components/file-version/template.hbs new file mode 100644 index 000000000..2e453920f --- /dev/null +++ b/tests/dummy/app/components/file-version/template.hbs @@ -0,0 +1,6 @@ +
  • +
    {{model.id}}
    +
    {{model.size}}
    +
    {{model.contentType}}
    +
  • +{{yield}} diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs index b00d399d7..ea4498438 100644 --- a/tests/dummy/app/templates/file.hbs +++ b/tests/dummy/app/templates/file.hbs @@ -15,11 +15,7 @@

    Versions

      {{#each model.versions as |version|}} -
    • -
      {{version.id}}
      -
      {{version.size}}
      -
      {{version.contentType}}
      -
    • + {{file-version model=version}} {{else}} (none) {{/each}} From 5b1118f73c504842490d284f805c508588a4cf9a Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Wed, 18 May 2016 15:31:06 -0400 Subject: [PATCH 203/959] Add comment-detail component --- tests/dummy/app/components/comment-detail/component.js | 6 ++++++ tests/dummy/app/components/comment-detail/template.hbs | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 tests/dummy/app/components/comment-detail/component.js create mode 100644 tests/dummy/app/components/comment-detail/template.hbs diff --git a/tests/dummy/app/components/comment-detail/component.js b/tests/dummy/app/components/comment-detail/component.js new file mode 100644 index 000000000..8ef0d629f --- /dev/null +++ b/tests/dummy/app/components/comment-detail/component.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; +import layout from './template'; + +export default Ember.Component.extend({ + layout +}); diff --git a/tests/dummy/app/components/comment-detail/template.hbs b/tests/dummy/app/components/comment-detail/template.hbs new file mode 100644 index 000000000..142414d6c --- /dev/null +++ b/tests/dummy/app/components/comment-detail/template.hbs @@ -0,0 +1,4 @@ +
    • +
      {{model.content}}
      +
    • +{{yield}} From bfc34df39edb67636c2b0808bd604f777413d3f0 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Wed, 18 May 2016 15:31:27 -0400 Subject: [PATCH 204/959] Use comment component in file detail page --- tests/dummy/app/templates/file.hbs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs index b00d399d7..3e9d434b9 100644 --- a/tests/dummy/app/templates/file.hbs +++ b/tests/dummy/app/templates/file.hbs @@ -28,12 +28,9 @@

      Comments

        {{#each model.comments as |comment|}} -
      • -
        {{comment.content}}
        -
      • + {{comment-detail model=comment}} {{else}} (none) {{/each}}
      -
    From f0c3738afd1ee428d6565c09934e47c7bf24e25f Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 18 May 2016 16:14:52 -0400 Subject: [PATCH 205/959] move logic to osf adapter --- addon/adapters/node.js | 17 +---------------- addon/adapters/osf-adapter.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index e9e0534fa..033e6a088 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -4,15 +4,6 @@ import isEnabled from 'ember-data/-private/features'; import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ - customSerialize: false, - findDirtyRelations(snapshot) { - var dirtyRelationships = snapshot.record.get('dirtyRelationships'); - return Object.keys(dirtyRelationships).filter(function(rel){ - var attr = snapshot._internalModel._relationships.get(rel); - var foo = Ember.get(dirtyRelationships, rel); - return attr && foo && Ember.get(attr.relationshipMeta.options, 'relationshipEndpoint'); - }); - }, buildURL(_, __, snapshot, requestType) { var self = this; if (requestType === 'updateRecord' && !snapshot.record.changedAttributes().length) { @@ -43,13 +34,7 @@ export default OsfAdapter.extend({ var id = snapshot.id; var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord'); if (url.indexOf('relationships') !== -1){ - var dirty = self.findDirtyRelations(snapshot)[0]; - var url_ = url.split('/'); - var relationType = url_[url_.indexOf('relationships') + 1]; - var dirtyList = snapshot._internalModel._relationships.get(dirty).members.list; - data = {data: dirtyList.map(function(item){ - return {type: relationType, id: item.id} - })} + data = self.relationshipPayload(snapshot, url); } else { var serializer = store.serializerFor(type.modelName); serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index 5328213b1..406b29ef0 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -19,5 +19,22 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { url += '/'; } return url; - } + }, + findDirtyRelations(snapshot) { + var dirtyRelationships = snapshot.record.get('dirtyRelationships'); + return Object.keys(dirtyRelationships).filter(function(rel){ + var attr = snapshot._internalModel._relationships.get(rel); + var foo = Ember.get(dirtyRelationships, rel); + return attr && foo && Ember.get(attr.relationshipMeta.options, 'relationshipEndpoint'); + }); + }, + relationshipPayload(snapshot, url){ + var dirty = this.findDirtyRelations(snapshot)[0]; + var url_ = url.split('/'); + var relationType = url_[url_.indexOf('relationships') + 1]; + var dirtyList = snapshot._internalModel._relationships.get(dirty).members.list; + return {data: dirtyList.map(function(item){ + return {type: relationType, id: item.id} + })} + }, }); From 70cf6c38cf77b916f95bda125d9c452d1c8e2180 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 18 May 2016 16:50:47 -0400 Subject: [PATCH 206/959] Add handlebars style linting --- .template-lintrc.js | 6 ++ package.json | 2 + .../app/components/files-tree/template.hbs | 20 ++-- .../app/components/log-detail/template.hbs | 27 +++--- tests/dummy/app/templates/file.hbs | 31 +++--- .../app/templates/institutions/detail.hbs | 16 ++-- .../app/templates/institutions/index.hbs | 26 ++--- tests/dummy/app/templates/nodes/detail.hbs | 59 +++++------- tests/dummy/app/templates/nodes/index.hbs | 40 ++++---- .../app/templates/registrations/detail.hbs | 5 +- .../app/templates/registrations/index.hbs | 24 ++--- tests/dummy/app/templates/users/detail.hbs | 94 +++++++++---------- tests/dummy/app/templates/users/index.hbs | 26 ++--- 13 files changed, 186 insertions(+), 190 deletions(-) create mode 100644 .template-lintrc.js diff --git a/.template-lintrc.js b/.template-lintrc.js new file mode 100644 index 000000000..483261e8d --- /dev/null +++ b/.template-lintrc.js @@ -0,0 +1,6 @@ +/* jshint node:true */ +'use strict'; + +module.exports = { + extends: 'recommended' +}; diff --git a/package.json b/package.json index 653a3592a..e84d76642 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "license": "MIT", "devDependencies": { "broccoli-asset-rev": "^2.2.0", + "chalk": "^1.1.3", "ember-a11y": "0.1.8", "ember-a11y-testing": "0.0.5", "ember-ajax": "0.7.1", @@ -33,6 +34,7 @@ "ember-cli-release": "0.2.8", "ember-cli-sass": "5.3.1", "ember-cli-sri": "^2.0.0", + "ember-cli-template-lint": "0.4.7", "ember-cli-uglify": "^1.2.0", "ember-component-css": "0.1.9", "ember-data": "^2.3.0", diff --git a/tests/dummy/app/components/files-tree/template.hbs b/tests/dummy/app/components/files-tree/template.hbs index 4589ecb3b..e6fe41e0f 100644 --- a/tests/dummy/app/components/files-tree/template.hbs +++ b/tests/dummy/app/components/files-tree/template.hbs @@ -1,12 +1,12 @@

    - - {{#if model.isFolder}} -

    - {{#each model.files as |file|}} - {{files-tree model=file}} - {{/each}} -

    - {{else}} - ({{link-to 'details' 'file' model}}) - {{/if}} + + {{#if model.isFolder}} +

    + {{#each model.files as |file|}} + {{files-tree model=file}} + {{/each}} +

    + {{else}} + ({{link-to 'details' 'file' model}}) + {{/if}}

    diff --git a/tests/dummy/app/components/log-detail/template.hbs b/tests/dummy/app/components/log-detail/template.hbs index 74a08ab78..0d7f7ecc0 100644 --- a/tests/dummy/app/components/log-detail/template.hbs +++ b/tests/dummy/app/components/log-detail/template.hbs @@ -10,18 +10,19 @@
    {{#each node-logs as |node-log|}} - - - - - - - - + + + + + + + + {{/each}}
    + Rename: + + {{input value=newName}} + + +
    + Delete: + + +
    @@ -20,29 +43,6 @@ {{input type='file' change=(action 'uploadFile')}}
    - Rename: - - {{input value=newName}} - - -
    - Delete: - - -
    From c11857a0369de11192415a3b3100413f76c2a6c6 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 17 May 2016 17:35:03 -0400 Subject: [PATCH 193/959] Stash some changes before merging with develop [ci skip] --- addon/authenticators/osf-cookie.js | 31 +++++++++++++++++++++ addon/authenticators/osf-token.js | 5 ++-- addon/mixins/osf-cookie-login-controller.js | 13 +++++++-- addon/mixins/osf-cookie-login-route.js | 21 ++++++++++++++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 addon/authenticators/osf-cookie.js create mode 100644 addon/mixins/osf-cookie-login-route.js diff --git a/addon/authenticators/osf-cookie.js b/addon/authenticators/osf-cookie.js new file mode 100644 index 000000000..6132bbd5c --- /dev/null +++ b/addon/authenticators/osf-cookie.js @@ -0,0 +1,31 @@ +import Ember from 'ember'; +import Base from 'ember-simple-auth/authenticators/base'; + +import config from 'ember-get-config'; + + +export default Base.extend({ + _test() { + return Ember.$.ajax({ + method: 'GET', + url: `${config.OSF.apiUrl}/${config.OSF.apiNamespace}/users/me/`, + dataType: 'json', + contentType: 'application/json', + xhrFields: { + withCredentials: true + } + }).then(function(res) { + return res.data; + }); + }, + restore(/* data */) { + return this._test().fail(this.invalidate); + }, + + authenticate(code) { + // For now, authentication consists of sending the user to OSF + return Ember.$.get({url: config.OSF.url + 'ticket=' + code}) + .then(()=> console.log(...arguments)); + // TODO: rv? + } +}); diff --git a/addon/authenticators/osf-token.js b/addon/authenticators/osf-token.js index 9e8e100be..44137eb96 100644 --- a/addon/authenticators/osf-token.js +++ b/addon/authenticators/osf-token.js @@ -4,8 +4,8 @@ import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; import config from 'ember-get-config'; export default BaseAuthenticator.extend({ - store: Ember.inject.service(), - authUrl: `${config.OSF.authUrl}/`, + store: Ember.inject.service(), // TODO: Possibly unused? + authUrl: `${config.OSF.authUrl}/`, // TODO: Where is this used? (not in OSF code or ember-simple-auth source that I can find) _test(accessToken) { return Ember.$.ajax({ method: 'GET', @@ -28,6 +28,7 @@ export default BaseAuthenticator.extend({ return this._test(accessToken).fail(this.invalidate); }, authenticate(accessToken) { + // Adds the entire API user endpoint record to the session store as given return this._test(accessToken); } }); diff --git a/addon/mixins/osf-cookie-login-controller.js b/addon/mixins/osf-cookie-login-controller.js index e89eec99e..3db17f91a 100644 --- a/addon/mixins/osf-cookie-login-controller.js +++ b/addon/mixins/osf-cookie-login-controller.js @@ -10,9 +10,16 @@ import Ember from 'ember'; export default Ember.Mixin.create({ session: Ember.inject.service('session'), - actions: { - loginHandler: function () { - console.log('Called submit', ...arguments); + queryParams: ['ticket'], + ticket: null, + + errorMessage: undefined, + + actions: { // TODO: What does submit do in the new scheme? + loginHandler: function (username, password) { + console.log('Called submit', username, password); + //this.get('session').authenticate('authenticator:osf-cookie', username, password) + // .catch((reason) => this.set('errorMessage', reason.error || reason)); return true; } } diff --git a/addon/mixins/osf-cookie-login-route.js b/addon/mixins/osf-cookie-login-route.js new file mode 100644 index 000000000..8aa628570 --- /dev/null +++ b/addon/mixins/osf-cookie-login-route.js @@ -0,0 +1,21 @@ +import Ember from 'ember'; + +import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin'; +//import config from 'ember-get-config'; + + +export default Ember.Mixin.create(UnauthenticatedRouteMixin, { + session: Ember.inject.service(), + beforeModel() { + // Login flow with cookies depends on being redirected to the /login page, to work around CORS issues + + // Check whether there is a ticket appended to the URL; if so, try to authenticate with it. (hitting this route implies user is unauthenticated) + // Otherwise show login form. + let params = this.paramsFor(this.routeName); + if (params.ticket) { + console.log("I found a ticket!", params.ticket); + return this.get('session').authenticate('authenticator:osf-cookie', params.ticket) + .then(()=> this.transitionTo('index')); // todo: is this transition necessary? + } + } +}); From ba0d0dfdaaeffdaa10fdec95c557e7fcd355deb8 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 18 May 2016 09:21:09 -0400 Subject: [PATCH 194/959] Rename files-tree => file-tree Because it was bugging me. [skip ci] --- .../dummy/app/components/{files-tree => file-tree}/component.js | 0 tests/dummy/app/components/{files-tree => file-tree}/style.scss | 0 .../dummy/app/components/{files-tree => file-tree}/template.hbs | 0 tests/dummy/app/templates/nodes/detail/files/index.hbs | 2 +- tests/dummy/app/templates/nodes/detail/files/provider/file.hbs | 2 +- tests/dummy/app/templates/nodes/detail/files/provider/index.hbs | 2 +- 6 files changed, 3 insertions(+), 3 deletions(-) rename tests/dummy/app/components/{files-tree => file-tree}/component.js (100%) rename tests/dummy/app/components/{files-tree => file-tree}/style.scss (100%) rename tests/dummy/app/components/{files-tree => file-tree}/template.hbs (100%) diff --git a/tests/dummy/app/components/files-tree/component.js b/tests/dummy/app/components/file-tree/component.js similarity index 100% rename from tests/dummy/app/components/files-tree/component.js rename to tests/dummy/app/components/file-tree/component.js diff --git a/tests/dummy/app/components/files-tree/style.scss b/tests/dummy/app/components/file-tree/style.scss similarity index 100% rename from tests/dummy/app/components/files-tree/style.scss rename to tests/dummy/app/components/file-tree/style.scss diff --git a/tests/dummy/app/components/files-tree/template.hbs b/tests/dummy/app/components/file-tree/template.hbs similarity index 100% rename from tests/dummy/app/components/files-tree/template.hbs rename to tests/dummy/app/components/file-tree/template.hbs diff --git a/tests/dummy/app/templates/nodes/detail/files/index.hbs b/tests/dummy/app/templates/nodes/detail/files/index.hbs index 7ec44e201..7a6bcdee1 100644 --- a/tests/dummy/app/templates/nodes/detail/files/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/index.hbs @@ -1,6 +1,6 @@

    Files

    {{#each model as |provider|}} - {{files-tree root=provider node=provider.node}} + {{file-tree root=provider node=provider.node}} {{/each}}
    diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs index b94d58fbe..66fd135f8 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs @@ -21,7 +21,7 @@
    {{#if model.isFolder}}

    Files

    - {{files-tree root=model node=node}} + {{file-tree root=model node=node}} {{else}}

    Versions

    diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs index 8a85b8b86..5357f5c88 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs @@ -5,7 +5,7 @@

    {{model.name}}

    - {{files-tree root=model node=model.node}} + {{file-tree root=model node=model.node}}
    From 5f2088893f77dd4ff418eb381be6121cd3d72ce9 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 18 May 2016 10:46:40 -0400 Subject: [PATCH 195/959] Working (though kludgy) move/copy dummy interface [skip ci] --- addon/services/file-manager.js | 15 ++++++------ .../app/components/file-actions/component.js | 23 +++++++++++++++++++ .../app/components/file-actions/template.hbs | 20 ++++++++++++++++ .../app/components/file-tree/template.hbs | 4 ++-- .../nodes/detail/files/provider/file.hbs | 1 + .../nodes/detail/files/provider/index.hbs | 4 ++++ 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index 56a25462f..09676de71 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -58,8 +58,8 @@ export default Ember.Service.extend({ JSON.stringify({ action: 'rename', rename: newName })); }, - move(file, targetFolder, newName=null, replace=true, - node=null, provider=null, action='move') { + move(file, targetFolder, { newName=null, replace=true, + node=null, provider=null, action='move' }) { var url = file.get('links').move; var data = { action, @@ -79,13 +79,14 @@ export default Ember.Service.extend({ if (provider) { data.provider = provider; } - return this._waterbutlerRequest('POST', url, null, data); + return this._waterbutlerRequest('POST', url, null, + JSON.stringify(data)); }, - copy(file, targetFolder, newName=null, replace=true, - node=null, provider=null) { - return this.move(file, targetFolder, newName, replace, - node, provider, 'copy'); + copy(file, targetFolder, { newName=null, replace=true, + node=null, provider=null }) { + return this.move(file, targetFolder, + { newName, replace, node, provider, action: 'copy' }); }, deleteFile(file) { diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index e50c7dd50..266407e79 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -64,6 +64,29 @@ export default Ember.Component.extend({ file.get('parentFolder').get('files').removeObject(file); this.get('onChange')(); }); + }, + + moveFile(folderId) { + let file = this.get('file'); + let store = this.get('store'); + let folder = store.peekRecord('file', folderId); + if (!folder) { + folder = store.peekRecord('file-provider', folderId); + if (!folder) { + debugger; + } + // TODO errors + } + let options = { + node: this.get('moveNode'), + provider: folder.get('provider'), + replace: this.get('moveReplace'), + action: this.get('moveCopy') ? 'copy' : 'move', + newName: this.get('moveName') + }; + + let p = this.get('fileManager').move(file, folder, options); + p.then(() => this.get('onChange')); } } }); diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index d978293b8..51dc89ac0 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -21,6 +21,26 @@ Delete
    + Move to: + +
    Folder ID: {{input value=moveTarget}}
    +
    Node ID (optional): {{input value=moveNode}}
    +
    New name (optional): {{input value=moveName}}
    +
    +
    +
    + +
    Additional Params Included
    {{node-log.action}} {{node-log.originalNode.title}}: {{node-log.originalNode.id}} {{node-log.user.givenName}} {{node-log.node.title}}: {{node-log.node.id}} {{moment-format node-log.date}} {{#each-in node-log.params as |key value|}} - {{key}}, - {{/each-in}} - {{if node-log.linkedNode "linked_node"}} - {{if node-log.templateNode "template_node"}} -
    {{node-log.action}} {{node-log.originalNode.title}}: {{node-log.originalNode.id}} {{node-log.user.givenName}} {{node-log.node.title}}: {{node-log.node.id}} {{moment-format node-log.date}} + {{#each-in node-log.params as |key value|}} + {{key}}, + {{/each-in}} + {{if node-log.linkedNode "linked_node"}} + {{if node-log.templateNode "template_node"}} +
    diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs index b00d399d7..ed7cafa03 100644 --- a/tests/dummy/app/templates/file.hbs +++ b/tests/dummy/app/templates/file.hbs @@ -11,29 +11,28 @@

    {{model.dateCreated}}

    {{model.checkout}}

    -
    +

    Versions

      - {{#each model.versions as |version|}} -
    • + {{#each model.versions as |version|}} +
    • {{version.id}}
      {{version.size}}
      {{version.contentType}}
      -
    • - {{else}} - (none) - {{/each}} + + {{else}} + (none) + {{/each}}
    -
    +

    Comments

      - {{#each model.comments as |comment|}} -
    • + {{#each model.comments as |comment|}} +
    • {{comment.content}}
      -
    • - {{else}} - (none) - {{/each}} -
    - + + {{else}} + (none) + {{/each}} +
    diff --git a/tests/dummy/app/templates/institutions/detail.hbs b/tests/dummy/app/templates/institutions/detail.hbs index a9cf6102e..65d0c42fb 100644 --- a/tests/dummy/app/templates/institutions/detail.hbs +++ b/tests/dummy/app/templates/institutions/detail.hbs @@ -9,14 +9,14 @@

    - {{#each model.nodes as |node|}} - - {{node.title}} - - - {{node.description}} - - {{/each}} + {{#each model.nodes as |node|}} + + {{node.title}} + + + {{node.description}} + + {{/each}}

    diff --git a/tests/dummy/app/templates/institutions/index.hbs b/tests/dummy/app/templates/institutions/index.hbs index 1cb38ca8b..c72d51f70 100644 --- a/tests/dummy/app/templates/institutions/index.hbs +++ b/tests/dummy/app/templates/institutions/index.hbs @@ -1,16 +1,16 @@

    All Institutions

    {{#each model as |inst|}} -
    -
    -

    {{inst.name}}

    -

    {{inst.description}}

    -

    {{inst.logoPath}}

    -

    {{inst.authUrl}}

    -

    - - View on OSF - - {{link-to 'Detail' 'institutions.detail' inst.id class="btn btn-primary"}} -

    -
    +
    +
    +

    {{inst.name}}

    +

    {{inst.description}}

    +

    {{inst.logoPath}}

    +

    {{inst.authUrl}}

    +

    + + View on OSF + + {{link-to 'Detail' 'institutions.detail' inst.id class="btn btn-primary"}} +

    +
    {{/each}} diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index bdee11b0d..8f1818dbe 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -1,7 +1,6 @@ {{link-to 'Back to list' 'nodes' class="btn btn-default"}} -
    - -

    Data

    +
    +

    Data

    {{model.title}}

    {{model.category}}

    {{moment-format model.dateCreated}}

    @@ -12,42 +11,36 @@


    -

    Edit this node

    Title: {{input value=editedTitle}} - - -

    Contributors

    - - - - - - - {{#each model.contributors as |contrib|}} - - - - - {{/each}} -
    IDAuthor?
    {{contrib.id}}{{contrib.bibliographic}}
    - + +

    Contributors

    + + + + + + {{#each model.contributors as |contrib|}} + + + + + {{/each}} +
    IDAuthor?
    {{contrib.id}}{{contrib.bibliographic}}

    - {{#each model.affiliatedInstitutions as |inst|}} - - {{inst.name}} - - {{/each}} + {{#each model.affiliatedInstitutions as |inst|}} + + {{inst.name}} + + {{/each}}

    -

    Files

    - {{#each model.files as |provider|}} - {{files-tree model=provider}} - {{/each}} -
    - - {{log-detail node-logs=model.logs}} + {{#each model.files as |provider|}} + {{files-tree model=provider}} + {{/each}} +
    + {{log-detail node-logs=model.logs}}
    diff --git a/tests/dummy/app/templates/nodes/index.hbs b/tests/dummy/app/templates/nodes/index.hbs index 42c810a25..a40388439 100644 --- a/tests/dummy/app/templates/nodes/index.hbs +++ b/tests/dummy/app/templates/nodes/index.hbs @@ -1,27 +1,23 @@

    My Nodes

    - -
    - - {{input type="text" value=title placeholder="Node's title" required=true}} - - {{input type="text" value=description placeholder="Node's description"}} -

    + + {{input type="text" value=title placeholder="Node's title" required=true}} + + {{input type="text" value=description placeholder="Node's description"}} +

    - - {{#each model as |node|}} -
    -
    -

    {{node.title}}

    -

    {{node.category}}

    -

    {{moment-format node.dateCreated}}

    -

    {{moment-format node.dateModified}}

    -

    - - View on OSF - - {{link-to 'Detail' 'nodes.detail' node.id class="btn btn-primary"}} -

    -
    +
    +
    +

    {{node.title}}

    +

    {{node.category}}

    +

    {{moment-format node.dateCreated}}

    +

    {{moment-format node.dateModified}}

    +

    + + View on OSF + + {{link-to 'Detail' 'nodes.detail' node.id class="btn btn-primary"}} +

    +
    {{/each}} diff --git a/tests/dummy/app/templates/registrations/detail.hbs b/tests/dummy/app/templates/registrations/detail.hbs index 48ed6700a..711c7f091 100644 --- a/tests/dummy/app/templates/registrations/detail.hbs +++ b/tests/dummy/app/templates/registrations/detail.hbs @@ -8,10 +8,9 @@ View on OSF

    - -

    {{link-to 'Node Registered' 'nodes.detail' model.registeredFrom.id class="btn btn-warning"}} +

    + {{link-to 'Node Registered' 'nodes.detail' model.registeredFrom.id class="btn btn-warning"}}

    -
    {{log-detail node-logs=model.logs}}
    diff --git a/tests/dummy/app/templates/registrations/index.hbs b/tests/dummy/app/templates/registrations/index.hbs index 352db559a..27796316b 100644 --- a/tests/dummy/app/templates/registrations/index.hbs +++ b/tests/dummy/app/templates/registrations/index.hbs @@ -1,15 +1,15 @@

    My Registrations

    {{#each model as |registration|}} -
    -
    -

    {{registration.title}}

    -

    {{registration.category}}

    -

    {{moment-format registration.dateRegistered}}

    -

    - - View on OSF - - {{link-to 'Detail' 'registrations.detail' registration.id class="btn btn-primary"}} -

    -
    +
    +
    +

    {{registration.title}}

    +

    {{registration.category}}

    +

    {{moment-format registration.dateRegistered}}

    +

    + + View on OSF + + {{link-to 'Detail' 'registrations.detail' registration.id class="btn btn-primary"}} +

    +
    {{/each}} diff --git a/tests/dummy/app/templates/users/detail.hbs b/tests/dummy/app/templates/users/detail.hbs index 23f7a3bff..e97af6244 100644 --- a/tests/dummy/app/templates/users/detail.hbs +++ b/tests/dummy/app/templates/users/detail.hbs @@ -1,50 +1,50 @@ {{link-to 'Back to list' 'users' class="btn btn-default"}}
    -

    Data

    -

    {{model.fullName}}

    -

    {{moment-format model.dateRegistered}}

    -

    - - View on OSF - -

    -
    -

    Nodes

    - - - - - - {{#each model.nodes as |node|}} - - - - - {{/each}} -
    IDTitle
    {{node.id}}{{node.title}}
    -
    -

    Registrations

    - - - - - - {{#each model.registrations as |registration|}} - - - - - {{/each}} -
    IDTitle
    {{registration.id}}{{registration.title}}
    -
    -

    Affiliated Institutions

    -

    - - {{#each model.affiliatedInstitutions as |inst|}} - - {{inst.name}} - - {{/each}} -
    -

    +

    Data

    +

    {{model.fullName}}

    +

    {{moment-format model.dateRegistered}}

    +

    + + View on OSF + +

    +
    +

    Nodes

    + + + + + + {{#each model.nodes as |node|}} + + + + + {{/each}} +
    IDTitle
    {{node.id}}{{node.title}}
    +
    +

    Registrations

    + + + + + + {{#each model.registrations as |registration|}} + + + + + {{/each}} +
    IDTitle
    {{registration.id}}{{registration.title}}
    +
    +

    Affiliated Institutions

    +

    + + {{#each model.affiliatedInstitutions as |inst|}} + + {{inst.name}} + + {{/each}} +
    +

    diff --git a/tests/dummy/app/templates/users/index.hbs b/tests/dummy/app/templates/users/index.hbs index 75ef77958..3bda43461 100644 --- a/tests/dummy/app/templates/users/index.hbs +++ b/tests/dummy/app/templates/users/index.hbs @@ -1,15 +1,15 @@

    Users

    -
    +
    {{#each model as |user|}} -
    -

    {{user.fullName}}

    -

    {{moment-format user.dateRegistered}}

    -
    -

    - - View on OSF - - {{link-to 'Detail' 'users.detail' user.id class="btn btn-primary"}} -

    -
    -{{/each}} \ No newline at end of file +
    +

    {{user.fullName}}

    +

    {{moment-format user.dateRegistered}}

    +
    +

    + + View on OSF + + {{link-to 'Detail' 'users.detail' user.id class="btn btn-primary"}} +

    +
    +{{/each}} From 7344c34bc280d6673435568fecb8f360fc1e0116 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 18 May 2016 17:09:17 -0400 Subject: [PATCH 207/959] Add template for updating contributor. --- tests/dummy/app/templates/nodes/detail.hbs | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 4130e928d..67592da83 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -25,33 +25,39 @@ Permissions Bibliographic + {{#each model.contributors as |contrib|}} {{contrib.id}} - {{contrib.permission}} - {{contrib.bibliographic}} + + + {{/each}} +

    Add contributor

    - {{input value=contributorID}}
    - -
    - {{radio-button name="permission" value="read" checked=contributorPermissions}} Read
    - {{radio-button name="permission" value="write" checked=contributorPermissions}} Read + Write
    - {{radio-button name="permission" value="admin" checked=contributorPermissions}} Administrator
    + {{input value=contributorID}} -
    - {{radio-button name="bibliographic" value=1 checked=bibliographic}} Bibliographic
    - {{radio-button name="bibliographic" value=0 checked=bibliographic}} Non-Bibliographic
    + +

    {{radio-button name="permission" value="read" checked=contributorPermissions}} Read + {{radio-button name="permission" value="write" checked=contributorPermissions}} Read + Write + {{radio-button name="permission" value="admin" checked=contributorPermissions}} Administrator

    -
    + +

    {{radio-button name="bibliographic" value=1 checked=bibliographic}} Bibliographic + {{radio-button name="bibliographic" value=0 checked=bibliographic}} Non-Bibliographic

    +
    From 264769ba714746a6c390d36d7a5ee21b129ee3a0 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 18 May 2016 17:10:40 -0400 Subject: [PATCH 208/959] Write helpers to determine which permission option and bibliographic option should be selected on initial load. --- tests/dummy/app/helpers/bibliographic-helper.js | 11 +++++++++++ tests/dummy/app/helpers/permission-helper.js | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/dummy/app/helpers/bibliographic-helper.js create mode 100644 tests/dummy/app/helpers/permission-helper.js diff --git a/tests/dummy/app/helpers/bibliographic-helper.js b/tests/dummy/app/helpers/bibliographic-helper.js new file mode 100644 index 000000000..4533c8d03 --- /dev/null +++ b/tests/dummy/app/helpers/bibliographic-helper.js @@ -0,0 +1,11 @@ +import Ember from 'ember'; + +export function bibliographicHelper(params) { + // checks if bibliographic is true or false + if (params[0]) { + return 'checked'; + } + return null; +} + +export default Ember.Helper.helper(bibliographicHelper); diff --git a/tests/dummy/app/helpers/permission-helper.js b/tests/dummy/app/helpers/permission-helper.js new file mode 100644 index 000000000..b9bbdba05 --- /dev/null +++ b/tests/dummy/app/helpers/permission-helper.js @@ -0,0 +1,10 @@ +import Ember from 'ember'; + +export function permissionHelper(params) { + if (params[0] === params[1]) { + return 'selected'; + } + return null; +} + +export default Ember.Helper.helper(permissionHelper); From 3f1391938cbc37348343c7a935dd70ec4b23eed8 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 18 May 2016 17:11:27 -0400 Subject: [PATCH 209/959] Add controller actions for creating objects containing all the permissions/bibliographic information that has been changed. --- tests/dummy/app/controllers/nodes/detail.js | 21 +++++++++++++++++++ .../unit/helpers/bibliographic-helper-test.js | 10 +++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/dummy/app/controllers/nodes/detail.js create mode 100644 tests/unit/helpers/bibliographic-helper-test.js diff --git a/tests/dummy/app/controllers/nodes/detail.js b/tests/dummy/app/controllers/nodes/detail.js new file mode 100644 index 000000000..29f52e738 --- /dev/null +++ b/tests/dummy/app/controllers/nodes/detail.js @@ -0,0 +1,21 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + editedPermissions: {}, + editedBibliographic: {}, + actions: { + permissionChange(permission) { + // Adds updated permissions for a certain contributor + var p = permission.split(' '); + var permissions = p[0]; + var contributorId = p[1]; + this.editedPermissions[contributorId] = permissions; + }, + bibliographicChange(target) { + // Adds updated bibliographic info for a certain contributor + var bibliographic = target.checked; + var contributorId = target.value; + this.editedBibliographic[contributorId] = bibliographic; + } + } +}); diff --git a/tests/unit/helpers/bibliographic-helper-test.js b/tests/unit/helpers/bibliographic-helper-test.js new file mode 100644 index 000000000..50a824076 --- /dev/null +++ b/tests/unit/helpers/bibliographic-helper-test.js @@ -0,0 +1,10 @@ +import { bibliographicHelper } from 'dummy/helpers/bibliographic-helper'; +import { module, test } from 'qunit'; + +module('Unit | Helper | bibliographic helper'); + +// Replace this with your real tests. +test('it works', function(assert) { + let result = bibliographicHelper([42]); + assert.ok(result); +}); From a166f3582dcd5eda55af72182136e3aee57936e7 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 18 May 2016 17:13:01 -0400 Subject: [PATCH 210/959] Modify method to work for both update/delete contributor actions. Checks to see if action is permissible. --- tests/dummy/app/routes/nodes/detail.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index fecc0ee56..ae4407422 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -64,13 +64,22 @@ export default Ember.Route.extend({ } } }, - canRemoveContributor(contribRemoving, contribMap) { - /** Contributor can only be removed if there is at least one other contributor - with admin permissions, and at least one other bibliographic contributor **/ + + generateContributorMap(contributors) { + // Maps all node contributors to format {contribID: {permission: "read|write|admin", bibliographic: "true|false"}} + var contribMap = contributors.content.currentState.reduce(function(newMap, contrib) { + newMap[contrib.id] = { permission: contrib._data.permission, bibliographic: contrib._data.bibliographic }; + return newMap; + }, {}); + return contribMap; + }, + canModifyContributor(contribRemoving, contribMap) { + /** Checks to see if contributor(s) can be updated/removed. Contributor can only be updated/removed + if there is at least one other contributor with admin permissions, and at least one other bibliographic contributor **/ var bibliographic = false; var admin = false; for (var contribId in contribMap) { - if (contribId === contribRemoving.id) { + if (contribRemoving && contribId === contribRemoving.id) { continue; } else { if (contribMap[contribId].bibliographic) { From 7bd1d84b84c518fc2e4847d4717d82be7dc917b3 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 18 May 2016 17:13:25 -0400 Subject: [PATCH 211/959] Add method that attempts to update contributors. --- tests/dummy/app/routes/nodes/detail.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index ae4407422..2cc8f6fbd 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -96,8 +96,32 @@ export default Ember.Route.extend({ return false; }, + attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic) { + if (this.canModifyContributor(null, contribMap)) { + for (var contrib in editedPermissions) { + this.store.findRecord('contributor', contrib).then(function(contributor) { + contributor.set('nodeId', node.id); + contributor.set('permission', editedPermissions[contrib]); + contributor.save(); + }); + } + for (var c in editedBibliographic) { + this.store.findRecord('contributor', c).then(function(contributor) { + debugger + contributor.set('nodeId', node.id); + contributor.set('bibliographic', editedBibliographic[c]); + contributor.save(); + }); + } + node.save(); + console.log('Contributor(s) updated.'); + } else { + console.log('Cannot update contributor(s)'); + } + }, + attemptContributorRemoval(contrib, contribMap, node) { - if (this.canRemoveContributor(contrib, contribMap)) { + if (this.canModifyContributor(contrib, contribMap)) { node.get('contributors').removeObject(contrib); contrib.deleteRecord(); node.save(); From 70c7eee3776d1216ac25bf62790b32fe86870675 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 18 May 2016 17:13:41 -0400 Subject: [PATCH 212/959] Add updateContributors action. --- tests/dummy/app/routes/nodes/detail.js | 30 ++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 2cc8f6fbd..2aaab38c6 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -42,15 +42,37 @@ export default Ember.Route.extend({ console.log('User ID must be specified.'); } }, + updateContributors(editedPermissions, editedBibliographic) { + var node = this.modelFor(this.routeName); + var contribMap = this.generateContributorMap(node.get('contributors')); + let user = this.modelFor('application'); + + for (var contrib in editedPermissions) { + contribMap[contrib].permission = editedPermissions[contrib]; + } + + for (var c in editedBibliographic) { + contribMap[c].bibliographic = editedBibliographic[c]; + } + + if (node.get('currentUserPermissions').indexOf('admin') !== -1) { + this.attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic); + } else { + // Non-admins can only attempt to remove themselves as contributors + if (contrib.id === user.id) { + this.attemptContributorsUpdate(contribMap, node); + } else { + console.log('Non-admins cannot update other contributors.'); + } + } + + }, deleteContributor(contrib) { var node = this.modelFor(this.routeName); contrib.setProperties({ nodeId: node.id }); let user = this.modelFor('application'); - var contribMap = node.get('contributors').content.currentState.reduce(function(newMap, contrib) { - newMap[contrib.id] = { permission: contrib._data.permission, bibliographic: contrib._data.bibliographic }; - return newMap; - }, {}); + var contribMap = this.generateContributorMap(node.get('contributors')); if (node.get('currentUserPermissions').indexOf('admin') !== -1) { this.attemptContributorRemoval(contrib, contribMap, node); From 07e0f9ecd3ef467be9926d0435e1a02c9da3da16 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 18 May 2016 17:20:46 -0400 Subject: [PATCH 213/959] Keep the store in sync after file-manager actions ...mostly [skip ci] --- addon/services/file-manager.js | 97 +++++++++++++------ .../app/components/file-actions/component.js | 4 +- 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index 09676de71..1cb5c882e 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -16,9 +16,8 @@ export default Ember.Service.extend({ updateContents(file, contents) { var url = file.get('links').upload; - return this._waterbutlerRequest('PUT', url, { - kind: 'file' - }, contents); + var params = { kind: 'file' }; + return this._waterbutlerRequest('PUT', url, params); }, checkout(file, user) { @@ -28,41 +27,57 @@ export default Ember.Service.extend({ // Folder actions addSubfolder(folder, name) { - var url = folder.get('links').new_folder; - var params = { + let url = folder.get('links').new_folder; + let params = { name, kind: 'folder' }; - // HACK: This is the only link that already has a query string - if (url.search(/\?kind=folder$/) > -1) { - url = `${url}&name=${name}`; - params = undefined; + // HACK: This is the only WB link that already has a query string + let queryStart = url.search(/\?kind=folder$/); + if (queryStart > -1) { + url = url.slice(0, queryStart); } - return this._waterbutlerRequest('PUT', url, params); + let store = this.get('store'); + + let p = this._waterbutlerRequest('PUT', url, params); + return p.then((data) => { + // TODO: figure out how to force a reload that actually works + this.get('store').findRecord('file', folder.get('id'), {reload: true}); + }); + }, uploadFile(folder, name, contents) { var url = folder.get('links').upload; - return this._waterbutlerRequest('PUT', url, { + var params = { name, kind: 'file' - }, contents); + }; + var p = this._waterbutlerRequest('PUT', url, params, contents); + return p.then((data) => { + // TODO: figure out how to force a reload that actually works + this.get('store').findRecord('file', folder.get('id'), {reload: true}); + }); }, // File and folder actions rename(file, newName) { var url = file.get('links').move; - return this._waterbutlerRequest('POST', url, null, - JSON.stringify({ action: 'rename', rename: newName })); + var data = JSON.stringify({ action: 'rename', rename: newName }); + var p = this._waterbutlerRequest('POST', url, null, data); + return p.then((data) => { + data.data.id = file.get('id'); + return this._addFileToStore(data); + }); }, move(file, targetFolder, { newName=null, replace=true, - node=null, provider=null, action='move' }) { + node=null, provider=null, copy=false }) { var url = file.get('links').move; var data = { - action, + action: copy ? 'copy' : 'move', path: targetFolder.get('path'), conflict: replace ? 'replace' : 'keep' }; @@ -79,32 +94,43 @@ export default Ember.Service.extend({ if (provider) { data.provider = provider; } - return this._waterbutlerRequest('POST', url, null, - JSON.stringify(data)); + + var p = this._waterbutlerRequest('POST', url, null, JSON.stringify(data)); + return p.then((data) => { + if (!copy) { + data.data.id = file.get('id'); + } + // TODO force reload on copy + return this._addFileToStore(data, targetFolder); + }); }, copy(file, targetFolder, { newName=null, replace=true, node=null, provider=null }) { return this.move(file, targetFolder, - { newName, replace, node, provider, action: 'copy' }); + { newName, replace, node, provider, copy: true }); }, deleteFile(file) { var url = file.get('links').delete; - return this._waterbutlerRequest('DELETE', url); + var p = this._waterbutlerRequest('DELETE', url); + return p.then(() => { + let parentFolder = file.get('parentFolder'); + if (parentFolder) { + parentFolder.get('files').removeObject(file); + } + }); }, _waterbutlerRequest(method, url, queryParams=null, data=null) { - if (!url) { - return Ember.RSVP.Promise.reject('That file/folder has no link for that action!'); - } if (queryParams) { let queryString = Ember.$.param(queryParams); url = `${url}?${queryString}`; } var sessionData = this.get('session').get('data').authenticated; var accessToken = sessionData.attributes.accessToken; - return new Ember.RSVP.Promise(function(resolve, reject) { + + return new Ember.RSVP.Promise((resolve, reject) => { Ember.$.ajax(url, { method, data, @@ -112,13 +138,24 @@ export default Ember.Service.extend({ headers: { Authorization: `Bearer ${accessToken}` }, - error(_, __, errorMsg) { - reject(new Error(errorMsg)); - }, - success(response) { - resolve(response); - } + success: (data) => resolve(data), + fail: (_, __, error) => reject(error) }); }); + }, + + _addFileToStore(data, parentFolder) { + // Hack the Waterbutler entity to look like the file Ember expects + data.data.type = 'file'; + let attr = data.data.attributes; + attr.materializedPath = attr.materialized; + attr.dateModified = attr.modified; + + let newFolder = this.get('store').push(data); + + if (parentFolder) { + newFolder.set('parentFolder', parentFolder); + } + return newFolder; } }); diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index 266407e79..c63b9b473 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -28,7 +28,6 @@ export default Ember.Component.extend({ if (name) { let p = this.get('fileManager').addSubfolder(folder, name); p.then(() => { - this.get('store').unloadRecord(folder); this.get('onChange')(); }); } @@ -61,7 +60,6 @@ export default Ember.Component.extend({ let file = this.get('file'); let p = this.get('fileManager').deleteFile(file); p.then(() => { - file.get('parentFolder').get('files').removeObject(file); this.get('onChange')(); }); }, @@ -81,7 +79,7 @@ export default Ember.Component.extend({ node: this.get('moveNode'), provider: folder.get('provider'), replace: this.get('moveReplace'), - action: this.get('moveCopy') ? 'copy' : 'move', + copy: this.get('moveCopy'), newName: this.get('moveName') }; From 1893ca898b8a3ca7f2f2955e294f8f6870e5afb7 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Wed, 18 May 2016 17:49:09 -0400 Subject: [PATCH 214/959] Notes on experiments with serving from a child directory [ci skip] --- addon/authorizers/osf-cookie.js | 2 +- addon/mixins/osf-cookie-login-controller.js | 2 +- tests/dummy/config/environment.js | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addon/authorizers/osf-cookie.js b/addon/authorizers/osf-cookie.js index f030a4afe..357186ff6 100644 --- a/addon/authorizers/osf-cookie.js +++ b/addon/authorizers/osf-cookie.js @@ -5,6 +5,6 @@ export default Base.extend({ // xhr object should be accessible from outer closure // https://github.com/simplabs/ember-simple-auth/blob/bed56395e8ce0e376e28b6ea9a62a4e26585d875/addon/mixins/data-adapter-mixin.js console.log('confirm that xhr is available through closure', xhr); - //xhr.withCredentials = true; + xhr.withCredentials = true; } }); diff --git a/addon/mixins/osf-cookie-login-controller.js b/addon/mixins/osf-cookie-login-controller.js index 3db17f91a..1a1f0f362 100644 --- a/addon/mixins/osf-cookie-login-controller.js +++ b/addon/mixins/osf-cookie-login-controller.js @@ -15,7 +15,7 @@ export default Ember.Mixin.create({ errorMessage: undefined, - actions: { // TODO: What does submit do in the new scheme? + actions: { // TODO: What does submit do in the new scheme? Needs to be form post, so probably nothing loginHandler: function (username, password) { console.log('Called submit', username, password); //this.get('session').authenticate('authenticator:osf-cookie', username, password) diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index a15132b2b..230d8acec 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -15,8 +15,12 @@ module.exports = function(environment) { var ENV = { modulePrefix: 'dummy', environment: environment, - baseURL: '/', - locationType: 'auto', + + // Settings that may be helpful when serving from within another application (non-root directory) + //baseURL: '/static/ember-dist/', + //rootUrl: '/emberosf/', + locationType: 'auto', // hash + EmberENV: { FEATURES: { // Here you can enable experimental features on an ember canary build From a78f084e02ecd37d29de797fdc0c19d0b057cadd Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 18 May 2016 22:41:09 -0400 Subject: [PATCH 215/959] Check if certain permission/bibliographic information needs to be updated first. --- tests/dummy/app/routes/nodes/detail.js | 60 +++++++++++++++++++------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 2aaab38c6..409eb635e 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -42,25 +42,35 @@ export default Ember.Route.extend({ console.log('User ID must be specified.'); } }, - updateContributors(editedPermissions, editedBibliographic) { + updateContributors(editedPermissions, editedBibliographic, firstPerm, firstBib) { var node = this.modelFor(this.routeName); var contribMap = this.generateContributorMap(node.get('contributors')); let user = this.modelFor('application'); + var firstPerm; + var firstBib; for (var contrib in editedPermissions) { contribMap[contrib].permission = editedPermissions[contrib]; + if (editedPermissions[contrib]) { + firstPerm = contrib; + } } for (var c in editedBibliographic) { contribMap[c].bibliographic = editedBibliographic[c]; + if (editedBibliographic[c]) { + firstBib = c; + } } if (node.get('currentUserPermissions').indexOf('admin') !== -1) { - this.attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic); + this.attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic, + firstPerm, firstBib); } else { // Non-admins can only attempt to remove themselves as contributors if (contrib.id === user.id) { - this.attemptContributorsUpdate(contribMap, node); + this.attemptContributorsUpdate(contribMap, node, editedPermissions, + editedBibliographic, firstPerm, firstBib); } else { console.log('Non-admins cannot update other contributors.'); } @@ -118,22 +128,26 @@ export default Ember.Route.extend({ return false; }, - attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic) { + attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic, + firstPerm, firstBib) { + debugger; if (this.canModifyContributor(null, contribMap)) { + if (firstPerm) { + this.modifyPermissions(firstPerm, node, editedPermissions); + } + if (firstBib) { + this.modifyBibliographic(firstBib, node, editedBibliographic) + } + for (var contrib in editedPermissions) { - this.store.findRecord('contributor', contrib).then(function(contributor) { - contributor.set('nodeId', node.id); - contributor.set('permission', editedPermissions[contrib]); - contributor.save(); - }); + if (contrib !== firstPerm) { + this.modifyPermissions(contrib, node, editedPermissions); + } } for (var c in editedBibliographic) { - this.store.findRecord('contributor', c).then(function(contributor) { - debugger - contributor.set('nodeId', node.id); - contributor.set('bibliographic', editedBibliographic[c]); - contributor.save(); - }); + if (c !== firstBib) { + this.modifyBibliographic(c, node, editedBibliographic); + } } node.save(); console.log('Contributor(s) updated.'); @@ -142,6 +156,22 @@ export default Ember.Route.extend({ } }, + modifyPermissions(contrib, node, editedPermissions) { + this.store.findRecord('contributor', contrib).then(function(contributor) { + contributor.set('nodeId', node.id); + contributor.set('permission', editedPermissions[contrib]); + contributor.save(); + }); + }, + + modifyBibliographic(contrib, node, editedBibliographic) { + this.store.findRecord('contributor', contrib).then(function(contributor) { + contributor.set('nodeId', node.id); + contributor.set('bibliographic', editedBibliographic[contrib]); + contributor.save(); + }); + }, + attemptContributorRemoval(contrib, contribMap, node) { if (this.canModifyContributor(contrib, contribMap)) { node.get('contributors').removeObject(contrib); From b528449d22541aa2bb7904e793775b0edf016a9c Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 19 May 2016 00:23:16 -0400 Subject: [PATCH 216/959] Ember radio button install/linting errors. --- package.json | 182 +++++++++++---------- tests/dummy/app/routes/nodes/detail.js | 7 +- tests/dummy/app/templates/nodes/detail.hbs | 77 ++++----- 3 files changed, 134 insertions(+), 132 deletions(-) diff --git a/package.json b/package.json index e84d76642..6fe6622ad 100644 --- a/package.json +++ b/package.json @@ -1,93 +1,95 @@ { - "name": "ember-osf", - "version": "0.0.1", - "description": "Ember Data models for the OSF APIv2", - "directories": { - "doc": "doc", - "test": "tests" - }, - "scripts": { - "build": "ember build", - "start": "ember server", - "test": "ember test", - "check-style": "./node_modules/jscs/bin/jscs ." - }, - "repository": "", - "engines": { - "node": ">= 0.10.0" - }, - "author": "", - "license": "MIT", - "devDependencies": { - "broccoli-asset-rev": "^2.2.0", - "chalk": "^1.1.3", - "ember-a11y": "0.1.8", - "ember-a11y-testing": "0.0.5", - "ember-ajax": "0.7.1", - "ember-cli": "^2.4.3", - "ember-cli-app-version": "^1.0.0", - "ember-cli-bootstrap-sassy": "0.5.3", - "ember-cli-dependency-checker": "^1.2.0", - "ember-cli-inject-live-reload": "^1.3.1", - "ember-cli-mirage": "0.1.13", - "ember-cli-qunit": "^1.2.1", - "ember-cli-release": "0.2.8", - "ember-cli-sass": "5.3.1", - "ember-cli-sri": "^2.0.0", - "ember-cli-template-lint": "0.4.7", - "ember-cli-uglify": "^1.2.0", - "ember-component-css": "0.1.9", - "ember-data": "^2.3.0", - "ember-disable-prototype-extensions": "^1.0.0", - "ember-disable-proxy-controllers": "^1.0.1", - "ember-export-application-global": "^1.0.4", - "ember-i18n": "4.2.1", - "ember-load-initializers": "0.5.1", - "ember-resolver": "2.0.3", - "ember-sinon": "0.5.0", - "ember-sinon-qunit": "1.3.1", - "jscs": "^3.0.3", - "loader": "2.1.0", - "loader.js": "4.0.3", - "moment": "^2.13.0" - }, - "keywords": [ - "ember-addon" + "name": "ember-osf", + "version": "0.0.1", + "description": "Ember Data models for the OSF APIv2", + "directories": { + "doc": "doc", + "test": "tests" + }, + "scripts": { + "build": "ember build", + "start": "ember server", + "test": "ember test", + "check-style": "./node_modules/jscs/bin/jscs ." + }, + "repository": "", + "engines": { + "node": ">= 0.10.0" + }, + "author": "", + "license": "MIT", + "devDependencies": { + "broccoli-asset-rev": "^2.2.0", + "chalk": "^1.1.3", + "ember-a11y": "0.1.8", + "ember-a11y-testing": "0.0.5", + "ember-ajax": "0.7.1", + "ember-cli": "^2.4.3", + "ember-cli-app-version": "^1.0.0", + "ember-cli-bootstrap-sassy": "0.5.3", + "ember-cli-dependency-checker": "^1.2.0", + "ember-cli-inject-live-reload": "^1.3.1", + "ember-cli-mirage": "0.1.13", + "ember-cli-qunit": "^1.2.1", + "ember-cli-release": "0.2.8", + "ember-cli-sass": "5.3.1", + "ember-cli-sri": "^2.0.0", + "ember-cli-template-lint": "0.4.7", + "ember-cli-uglify": "^1.2.0", + "ember-component-css": "0.1.9", + "ember-data": "^2.3.0", + "ember-disable-prototype-extensions": "^1.0.0", + "ember-disable-proxy-controllers": "^1.0.1", + "ember-export-application-global": "^1.0.4", + "ember-i18n": "4.2.1", + "ember-load-initializers": "0.5.1", + "ember-radio-button": "1.0.7", + "ember-resolver": "2.0.3", + "ember-sinon": "0.5.0", + "ember-sinon-qunit": "1.3.1", + "jscs": "^3.0.3", + "loader": "2.1.0", + "loader.js": "4.0.3", + "moment": "^2.13.0" + }, + "keywords": [ + "ember-addon" + ], + "dependencies": { + "config": "^1.20.1", + "ember-cli-babel": "^5.1.5", + "ember-cli-htmlbars": "^1.0.1", + "ember-cli-htmlbars-inline-precompile": "^0.3.1", + "ember-cli-moment-shim": "1.1.0", + "ember-cli-node-assets": "^0.1.3", + "ember-get-config": "0.0.2", + "ember-moment": "6.1.0", + "ember-radio-buttons": "^4.0.1", + "ember-simple-auth": "1.1.0-beta.5", + "js-yaml": "^3.6.0" + }, + "ember-addon": { + "configPath": "tests/dummy/config" + }, + "jscsConfig": { + "preset": "airbnb", + "excludeFiles": [ + "bower_components", + "dist", + "tmp", + "vendor", + "app/locales", + "tests/unit", + "tests/integration", + "tests/helpers", + "tests/dummy/app/mirage" ], - "dependencies": { - "config": "^1.20.1", - "ember-cli-babel": "^5.1.5", - "ember-cli-htmlbars": "^1.0.1", - "ember-cli-htmlbars-inline-precompile": "^0.3.1", - "ember-cli-moment-shim": "1.1.0", - "ember-cli-node-assets": "^0.1.3", - "ember-get-config": "0.0.2", - "ember-moment": "6.1.0", - "ember-simple-auth": "1.1.0-beta.5", - "js-yaml": "^3.6.0" - }, - "ember-addon": { - "configPath": "tests/dummy/config" - }, - "jscsConfig": { - "preset": "airbnb", - "excludeFiles": [ - "bower_components", - "dist", - "tmp", - "vendor", - "app/locales", - "tests/unit", - "tests/integration", - "tests/helpers", - "tests/dummy/app/mirage" - ], - "requireSpacesInAnonymousFunctionExpression": false, - "requireTrailingComma": false, - "disallowTrailingComma": false, - "requirePaddingNewLinesAfterBlocks": false, - "validateIndentation": 4, - "requirePaddingNewLinesBeforeLineComments": false, - "maximumLineLength": false - } + "requireSpacesInAnonymousFunctionExpression": false, + "requireTrailingComma": false, + "disallowTrailingComma": false, + "requirePaddingNewLinesAfterBlocks": false, + "validateIndentation": 4, + "requirePaddingNewLinesBeforeLineComments": false, + "maximumLineLength": false + } } diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 409eb635e..76b87dcd1 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -42,7 +42,7 @@ export default Ember.Route.extend({ console.log('User ID must be specified.'); } }, - updateContributors(editedPermissions, editedBibliographic, firstPerm, firstBib) { + updateContributors(editedPermissions, editedBibliographic) { var node = this.modelFor(this.routeName); var contribMap = this.generateContributorMap(node.get('contributors')); let user = this.modelFor('application'); @@ -130,13 +130,12 @@ export default Ember.Route.extend({ attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic, firstPerm, firstBib) { - debugger; if (this.canModifyContributor(null, contribMap)) { if (firstPerm) { - this.modifyPermissions(firstPerm, node, editedPermissions); + this.modifyPermissions(firstPerm, node, editedPermissions); } if (firstBib) { - this.modifyBibliographic(firstBib, node, editedBibliographic) + this.modifyBibliographic(firstBib, node, editedBibliographic); } for (var contrib in editedPermissions) { diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index cc408e72b..2a3593c92 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -15,48 +15,49 @@ Title: {{input value=editedTitle}} -

    Contributors

    +

    Contributors

    + + + + + + + + {{#each model.contributors as |contrib|}} + + + + + + + {{/each}} +
    ID Permissions Bibliographic
    {{contrib.id}} + +
    + - - - - - - - - - {{#each model.contributors as |contrib|}} - - - - - - - {{/each}} -
    ID Permissions Bibliographic
    {{contrib.id}} -
    - - -
    - -

    Add contributor

    - {{input value=contributorID}} +
    - -

    {{radio-button name="permission" value="read" checked=contributorPermissions}} Read +

    Add contributor

    + {{input value=contributorID}} + +

    + {{radio-button name="permission" value="read" checked=contributorPermissions}} Read {{radio-button name="permission" value="write" checked=contributorPermissions}} Read + Write - {{radio-button name="permission" value="admin" checked=contributorPermissions}} Administrator

    - - -

    {{radio-button name="bibliographic" value=1 checked=bibliographic}} Bibliographic - {{radio-button name="bibliographic" value=0 checked=bibliographic}} Non-Bibliographic

    + {{radio-button name="permission" value="admin" checked=contributorPermissions}} Administrator +

    - -
    + +

    + {{radio-button name="bibliographic" value=1 checked=bibliographic}} Bibliographic + {{radio-button name="bibliographic" value=0 checked=bibliographic}} Non-Bibliographic +

    + +

    From 10c68650b0a20b85b9d0492b993b3b3534a08fe2 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 19 May 2016 09:34:17 -0400 Subject: [PATCH 217/959] Remove checks that ensure certain update contributors requests occur first. --- tests/dummy/app/routes/nodes/detail.js | 31 ++++------------------ tests/dummy/app/templates/nodes/detail.hbs | 5 ++-- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 76b87dcd1..3c42d754b 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -46,31 +46,22 @@ export default Ember.Route.extend({ var node = this.modelFor(this.routeName); var contribMap = this.generateContributorMap(node.get('contributors')); let user = this.modelFor('application'); - var firstPerm; - var firstBib; for (var contrib in editedPermissions) { contribMap[contrib].permission = editedPermissions[contrib]; - if (editedPermissions[contrib]) { - firstPerm = contrib; - } } for (var c in editedBibliographic) { contribMap[c].bibliographic = editedBibliographic[c]; - if (editedBibliographic[c]) { - firstBib = c; - } } if (node.get('currentUserPermissions').indexOf('admin') !== -1) { - this.attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic, - firstPerm, firstBib); + this.attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic); } else { // Non-admins can only attempt to remove themselves as contributors if (contrib.id === user.id) { this.attemptContributorsUpdate(contribMap, node, editedPermissions, - editedBibliographic, firstPerm, firstBib); + editedBibliographic); } else { console.log('Non-admins cannot update other contributors.'); } @@ -128,25 +119,13 @@ export default Ember.Route.extend({ return false; }, - attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic, - firstPerm, firstBib) { + attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic) { if (this.canModifyContributor(null, contribMap)) { - if (firstPerm) { - this.modifyPermissions(firstPerm, node, editedPermissions); - } - if (firstBib) { - this.modifyBibliographic(firstBib, node, editedBibliographic); - } - for (var contrib in editedPermissions) { - if (contrib !== firstPerm) { - this.modifyPermissions(contrib, node, editedPermissions); - } + this.modifyPermissions(contrib, node, editedPermissions); } for (var c in editedBibliographic) { - if (c !== firstBib) { - this.modifyBibliographic(c, node, editedBibliographic); - } + this.modifyBibliographic(c, node, editedBibliographic); } node.save(); console.log('Contributor(s) updated.'); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 2a3593c92..cb365de21 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -15,6 +15,7 @@ Title: {{input value=editedTitle}} +


    Contributors

    @@ -43,8 +44,8 @@

    Add contributor

    - {{input value=contributorID}} - +

    {{input value=contributorID}}

    +

    {{radio-button name="permission" value="read" checked=contributorPermissions}} Read {{radio-button name="permission" value="write" checked=contributorPermissions}} Read + Write From 54ca8aa976c0546f3d9661627f8d58abfb3da708 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 19 May 2016 09:47:58 -0400 Subject: [PATCH 218/959] Remove unnecessary modification of node relationship in contributor removal. --- tests/dummy/app/routes/nodes/detail.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 3c42d754b..a323f780d 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -152,9 +152,7 @@ export default Ember.Route.extend({ attemptContributorRemoval(contrib, contribMap, node) { if (this.canModifyContributor(contrib, contribMap)) { - node.get('contributors').removeObject(contrib); contrib.deleteRecord(); - node.save(); contrib.save(); console.log('Contributor removed.'); } else { From 988d804fde4ff749359e7d92ced6b3a3fdad28e3 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 19 May 2016 09:56:51 -0400 Subject: [PATCH 219/959] Remove unused var. --- tests/dummy/app/routes/nodes/detail.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index a323f780d..aa37273df 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -76,11 +76,11 @@ export default Ember.Route.extend({ var contribMap = this.generateContributorMap(node.get('contributors')); if (node.get('currentUserPermissions').indexOf('admin') !== -1) { - this.attemptContributorRemoval(contrib, contribMap, node); + this.attemptContributorRemoval(contrib, contribMap); } else { // Non-admins can only attempt to remove themselves as contributors if (contrib.id === user.id) { - this.attemptContributorRemoval(contrib, contribMap, node); + this.attemptContributorRemoval(contrib, contribMap); } else { console.log('Non-admins cannot delete other contributors.'); } @@ -150,7 +150,7 @@ export default Ember.Route.extend({ }); }, - attemptContributorRemoval(contrib, contribMap, node) { + attemptContributorRemoval(contrib, contribMap) { if (this.canModifyContributor(contrib, contribMap)) { contrib.deleteRecord(); contrib.save(); From e4881f77be9fefb1bddb8d63602c73dbd7324551 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 19 May 2016 10:22:10 -0400 Subject: [PATCH 220/959] Clean up merge for collections work h/t @gembarrett --- addon/adapters/collection.js | 4 ++++ addon/models/collection.js | 13 +++++++++++++ app/adapters/collection.js | 1 + app/models/collection.js | 1 + .../dummy/app/controllers/collections/index.js | 12 ++++++++++++ tests/dummy/app/router.js | 5 +++++ tests/dummy/app/routes/collections.js | 10 ++++++++++ tests/dummy/app/routes/collections/detail.js | 9 +++++++++ tests/dummy/app/templates/collections.hbs | 1 + .../dummy/app/templates/collections/detail.hbs | 6 ++++++ tests/dummy/app/templates/collections/index.hbs | 17 +++++++++++++++++ tests/dummy/app/templates/index.hbs | 1 + tests/unit/adapters/collection-test.js | 12 ++++++++++++ tests/unit/models/collections-test.js | 12 ++++++++++++ 14 files changed, 104 insertions(+) create mode 100644 addon/adapters/collection.js create mode 100644 addon/models/collection.js create mode 100644 app/adapters/collection.js create mode 100644 app/models/collection.js create mode 100644 tests/dummy/app/controllers/collections/index.js create mode 100644 tests/dummy/app/routes/collections.js create mode 100644 tests/dummy/app/routes/collections/detail.js create mode 100644 tests/dummy/app/templates/collections.hbs create mode 100644 tests/dummy/app/templates/collections/detail.hbs create mode 100644 tests/dummy/app/templates/collections/index.hbs create mode 100644 tests/unit/adapters/collection-test.js create mode 100644 tests/unit/models/collections-test.js diff --git a/addon/adapters/collection.js b/addon/adapters/collection.js new file mode 100644 index 000000000..5a903d089 --- /dev/null +++ b/addon/adapters/collection.js @@ -0,0 +1,4 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({ +}); diff --git a/addon/models/collection.js b/addon/models/collection.js new file mode 100644 index 000000000..ab49b53f8 --- /dev/null +++ b/addon/models/collection.js @@ -0,0 +1,13 @@ +import DS from 'ember-data'; + +import OsfModel from '../mixins/osf-model'; + +export default DS.Model.extend(OsfModel, { + title: DS.attr('string'), + dateCreated: DS.attr('date'), + dateModified: DS.attr('date'), + + // nodeLinks: DS.hasMany('node-pointers'), + // linkedNodes: DS.hasMany('node-pointers') + +}); diff --git a/app/adapters/collection.js b/app/adapters/collection.js new file mode 100644 index 000000000..e42ce8aec --- /dev/null +++ b/app/adapters/collection.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/collection'; diff --git a/app/models/collection.js b/app/models/collection.js new file mode 100644 index 000000000..5d0e23c03 --- /dev/null +++ b/app/models/collection.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/models/collection'; diff --git a/tests/dummy/app/controllers/collections/index.js b/tests/dummy/app/controllers/collections/index.js new file mode 100644 index 000000000..ca4f6384b --- /dev/null +++ b/tests/dummy/app/controllers/collections/index.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + actions: { + createCollection: function(title) { + var collection = this.store.createRecord('collection',{ + title: title, + }); + collection.save(); + } + } +}); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 741aabfe3..ecc401efa 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -34,6 +34,11 @@ Router.map(function() { path: '/file/:file_id' }); this.route('profile'); + this.route('collections', function() { + this.route('detail', { + path: '/:collection_id' + }); + }); }); export default Router; diff --git a/tests/dummy/app/routes/collections.js b/tests/dummy/app/routes/collections.js new file mode 100644 index 000000000..5c7ae4e39 --- /dev/null +++ b/tests/dummy/app/routes/collections.js @@ -0,0 +1,10 @@ +import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default Ember.Route.extend(AuthenticatedRouteMixin,{ + store: Ember.inject.service(), + session: Ember.inject.service(), + model() { + return this.get('store').findAll('collection'); + } +}); diff --git a/tests/dummy/app/routes/collections/detail.js b/tests/dummy/app/routes/collections/detail.js new file mode 100644 index 000000000..94eb07a88 --- /dev/null +++ b/tests/dummy/app/routes/collections/detail.js @@ -0,0 +1,9 @@ +import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; + +export default Ember.Route.extend(AuthenticatedRouteMixin, { + model(params) { + return this.store.findRecord('collection', params.collection_id); + }, + +}); diff --git a/tests/dummy/app/templates/collections.hbs b/tests/dummy/app/templates/collections.hbs new file mode 100644 index 000000000..c24cd6895 --- /dev/null +++ b/tests/dummy/app/templates/collections.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/tests/dummy/app/templates/collections/detail.hbs b/tests/dummy/app/templates/collections/detail.hbs new file mode 100644 index 000000000..be2b85311 --- /dev/null +++ b/tests/dummy/app/templates/collections/detail.hbs @@ -0,0 +1,6 @@ +{{link-to 'Back to list' 'collections' class="btn btn-default"}} +

    +

    {{model.title}}

    +

    {{moment-format model.dateCreated}}

    +

    {{moment-format model.dateModified}}

    +
    diff --git a/tests/dummy/app/templates/collections/index.hbs b/tests/dummy/app/templates/collections/index.hbs new file mode 100644 index 000000000..1281ec3a0 --- /dev/null +++ b/tests/dummy/app/templates/collections/index.hbs @@ -0,0 +1,17 @@ +

    Collections

    + +
    +
    Create Collection
    + {{input value=title placeholder="Collection's title" required=true}} + +
    +
    +
    +
    Collections list
    + {{#each model as |collection|}} +

    Title: {{collection.title}}

    +

    Date created: {{moment-format collection.dateCreated}}

    +

    Date modified: {{moment-format collection.dateModified}}

    + {{link-to "Detail" "collections.detail" collection.id class="btn btn-primary"}} + {{/each}} +
    diff --git a/tests/dummy/app/templates/index.hbs b/tests/dummy/app/templates/index.hbs index 07919019b..f75236068 100644 --- a/tests/dummy/app/templates/index.hbs +++ b/tests/dummy/app/templates/index.hbs @@ -3,3 +3,4 @@ {{link-to 'All Institutions' 'institutions' class="btn btn-danger"}} {{link-to 'Users' 'users' class="btn btn-default"}} {{link-to 'My Profile' 'profile' class="btn btn-default"}} +{{link-to 'Collections' 'collections' class="btn btn-default"}} diff --git a/tests/unit/adapters/collection-test.js b/tests/unit/adapters/collection-test.js new file mode 100644 index 000000000..bef509d72 --- /dev/null +++ b/tests/unit/adapters/collection-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:collection', 'Unit | Adapter | collection', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); diff --git a/tests/unit/models/collections-test.js b/tests/unit/models/collections-test.js new file mode 100644 index 000000000..28385b1de --- /dev/null +++ b/tests/unit/models/collections-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('collection', 'Unit | Model | collection', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); From c7d4513bb6d528a292b0bce99b97438ffceeb4a6 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 19 May 2016 10:42:09 -0400 Subject: [PATCH 221/959] JS styling fixes --- tests/dummy/app/controllers/collections/index.js | 14 +++++++------- tests/dummy/app/routes/collections.js | 12 ++++++------ tests/dummy/app/routes/collections/detail.js | 7 +++---- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/dummy/app/controllers/collections/index.js b/tests/dummy/app/controllers/collections/index.js index ca4f6384b..d6d489767 100644 --- a/tests/dummy/app/controllers/collections/index.js +++ b/tests/dummy/app/controllers/collections/index.js @@ -1,12 +1,12 @@ import Ember from 'ember'; export default Ember.Controller.extend({ - actions: { - createCollection: function(title) { - var collection = this.store.createRecord('collection',{ - title: title, - }); - collection.save(); + actions: { + createCollection: function(title) { + var collection = this.store.createRecord('collection', { + title: title + }); + collection.save(); + } } - } }); diff --git a/tests/dummy/app/routes/collections.js b/tests/dummy/app/routes/collections.js index 5c7ae4e39..07e65daaf 100644 --- a/tests/dummy/app/routes/collections.js +++ b/tests/dummy/app/routes/collections.js @@ -1,10 +1,10 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Ember.Route.extend(AuthenticatedRouteMixin,{ - store: Ember.inject.service(), - session: Ember.inject.service(), - model() { - return this.get('store').findAll('collection'); - } +export default Ember.Route.extend(AuthenticatedRouteMixin, { + store: Ember.inject.service(), + session: Ember.inject.service(), + model() { + return this.get('store').findAll('collection'); + } }); diff --git a/tests/dummy/app/routes/collections/detail.js b/tests/dummy/app/routes/collections/detail.js index 94eb07a88..de3de94a4 100644 --- a/tests/dummy/app/routes/collections/detail.js +++ b/tests/dummy/app/routes/collections/detail.js @@ -2,8 +2,7 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; export default Ember.Route.extend(AuthenticatedRouteMixin, { - model(params) { - return this.store.findRecord('collection', params.collection_id); - }, - + model(params) { + return this.store.findRecord('collection', params.collection_id); + } }); From 493e2dd65ae244e69e09a4f593b0cf7dd4e74a66 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 19 May 2016 10:55:17 -0400 Subject: [PATCH 222/959] Move sign-up component outside dummy app --- .../components/sign-up/component.js | 2 +- .../components/sign-up/style.css | 0 addon/components/sign-up/template.hbs | 60 +++++++++++++++++++ app/components/sign-up/component.js | 1 + .../dummy/app/components/sign-up/template.hbs | 58 ------------------ .../components/sign-up/component-test.js | 24 ++++++++ 6 files changed, 86 insertions(+), 59 deletions(-) rename {tests/dummy/app => addon}/components/sign-up/component.js (90%) rename {tests/dummy/app => addon}/components/sign-up/style.css (100%) create mode 100644 addon/components/sign-up/template.hbs create mode 100644 app/components/sign-up/component.js delete mode 100644 tests/dummy/app/components/sign-up/template.hbs create mode 100644 tests/integration/components/sign-up/component-test.js diff --git a/tests/dummy/app/components/sign-up/component.js b/addon/components/sign-up/component.js similarity index 90% rename from tests/dummy/app/components/sign-up/component.js rename to addon/components/sign-up/component.js index 44bf16cc0..8ef0d629f 100644 --- a/tests/dummy/app/components/sign-up/component.js +++ b/addon/components/sign-up/component.js @@ -2,5 +2,5 @@ import Ember from 'ember'; import layout from './template'; export default Ember.Component.extend({ - layout + layout }); diff --git a/tests/dummy/app/components/sign-up/style.css b/addon/components/sign-up/style.css similarity index 100% rename from tests/dummy/app/components/sign-up/style.css rename to addon/components/sign-up/style.css diff --git a/addon/components/sign-up/template.hbs b/addon/components/sign-up/template.hbs new file mode 100644 index 000000000..03d793f6c --- /dev/null +++ b/addon/components/sign-up/template.hbs @@ -0,0 +1,60 @@ + diff --git a/app/components/sign-up/component.js b/app/components/sign-up/component.js new file mode 100644 index 000000000..bb5fcad8a --- /dev/null +++ b/app/components/sign-up/component.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/sign-up/component'; \ No newline at end of file diff --git a/tests/dummy/app/components/sign-up/template.hbs b/tests/dummy/app/components/sign-up/template.hbs deleted file mode 100644 index 80ffbd7f3..000000000 --- a/tests/dummy/app/components/sign-up/template.hbs +++ /dev/null @@ -1,58 +0,0 @@ - \ No newline at end of file diff --git a/tests/integration/components/sign-up/component-test.js b/tests/integration/components/sign-up/component-test.js new file mode 100644 index 000000000..e7ae1c921 --- /dev/null +++ b/tests/integration/components/sign-up/component-test.js @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('sign-up', 'Integration | Component | sign up', { + integration: true +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.render(hbs`{{sign-up}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#sign-up}} + template block text + {{/sign-up}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); From 719703731020bbd8e3398a4782e6da63b1997025 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 19 May 2016 11:07:08 -0400 Subject: [PATCH 223/959] Move login-form component outside of dummy app --- .../components/login-form/component.js | 0 .../components/login-form/style.css | 0 addon/components/login-form/template.hbs | 44 ++++++++++++++++++ addon/components/sign-up/component.js | 2 +- app/components/login-form/component.js | 1 + app/components/sign-up/component.js | 2 +- .../app/components/login-form/template.hbs | 46 ------------------- .../components/login-form/component-test.js | 24 ++++++++++ 8 files changed, 71 insertions(+), 48 deletions(-) rename {tests/dummy/app => addon}/components/login-form/component.js (100%) rename {tests/dummy/app => addon}/components/login-form/style.css (100%) create mode 100644 addon/components/login-form/template.hbs create mode 100644 app/components/login-form/component.js delete mode 100644 tests/dummy/app/components/login-form/template.hbs create mode 100644 tests/integration/components/login-form/component-test.js diff --git a/tests/dummy/app/components/login-form/component.js b/addon/components/login-form/component.js similarity index 100% rename from tests/dummy/app/components/login-form/component.js rename to addon/components/login-form/component.js diff --git a/tests/dummy/app/components/login-form/style.css b/addon/components/login-form/style.css similarity index 100% rename from tests/dummy/app/components/login-form/style.css rename to addon/components/login-form/style.css diff --git a/addon/components/login-form/template.hbs b/addon/components/login-form/template.hbs new file mode 100644 index 000000000..4d6c83b6e --- /dev/null +++ b/addon/components/login-form/template.hbs @@ -0,0 +1,44 @@ + diff --git a/addon/components/sign-up/component.js b/addon/components/sign-up/component.js index 8ef0d629f..44bf16cc0 100644 --- a/addon/components/sign-up/component.js +++ b/addon/components/sign-up/component.js @@ -2,5 +2,5 @@ import Ember from 'ember'; import layout from './template'; export default Ember.Component.extend({ - layout + layout }); diff --git a/app/components/login-form/component.js b/app/components/login-form/component.js new file mode 100644 index 000000000..b83ae3edb --- /dev/null +++ b/app/components/login-form/component.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/login-form/component'; diff --git a/app/components/sign-up/component.js b/app/components/sign-up/component.js index bb5fcad8a..a51ac5c44 100644 --- a/app/components/sign-up/component.js +++ b/app/components/sign-up/component.js @@ -1 +1 @@ -export { default } from 'ember-osf/components/sign-up/component'; \ No newline at end of file +export { default } from 'ember-osf/components/sign-up/component'; diff --git a/tests/dummy/app/components/login-form/template.hbs b/tests/dummy/app/components/login-form/template.hbs deleted file mode 100644 index a5bb6607c..000000000 --- a/tests/dummy/app/components/login-form/template.hbs +++ /dev/null @@ -1,46 +0,0 @@ - \ No newline at end of file diff --git a/tests/integration/components/login-form/component-test.js b/tests/integration/components/login-form/component-test.js new file mode 100644 index 000000000..abfe9c141 --- /dev/null +++ b/tests/integration/components/login-form/component-test.js @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('login-form', 'Integration | Component | login form', { + integration: true +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.render(hbs`{{login-form}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#login-form}} + template block text + {{/login-form}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); From 669e4c29a3055c53bee7278cff9c133bc9bd9d0d Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 19 May 2016 10:40:07 -0400 Subject: [PATCH 224/959] Move component to addon/components --- .../components/file-version/component.js | 0 addon/components/file-version/template.hbs | 6 +++++ app/components/file-version/component.js | 1 + .../app/components/file-version/template.hbs | 6 ----- .../components/file-version/component-test.js | 24 +++++++++++++++++++ 5 files changed, 31 insertions(+), 6 deletions(-) rename {tests/dummy/app => addon}/components/file-version/component.js (100%) create mode 100644 addon/components/file-version/template.hbs create mode 100644 app/components/file-version/component.js delete mode 100644 tests/dummy/app/components/file-version/template.hbs create mode 100644 tests/integration/components/file-version/component-test.js diff --git a/tests/dummy/app/components/file-version/component.js b/addon/components/file-version/component.js similarity index 100% rename from tests/dummy/app/components/file-version/component.js rename to addon/components/file-version/component.js diff --git a/addon/components/file-version/template.hbs b/addon/components/file-version/template.hbs new file mode 100644 index 000000000..92b58285b --- /dev/null +++ b/addon/components/file-version/template.hbs @@ -0,0 +1,6 @@ +
  • +
    {{model.id}}
    +
    {{model.size}}
    +
    {{model.contentType}}
    +
  • +{{yield}} diff --git a/app/components/file-version/component.js b/app/components/file-version/component.js new file mode 100644 index 000000000..687ce0ba9 --- /dev/null +++ b/app/components/file-version/component.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/file-version/component'; diff --git a/tests/dummy/app/components/file-version/template.hbs b/tests/dummy/app/components/file-version/template.hbs deleted file mode 100644 index 2e453920f..000000000 --- a/tests/dummy/app/components/file-version/template.hbs +++ /dev/null @@ -1,6 +0,0 @@ -
  • -
    {{model.id}}
    -
    {{model.size}}
    -
    {{model.contentType}}
    -
  • -{{yield}} diff --git a/tests/integration/components/file-version/component-test.js b/tests/integration/components/file-version/component-test.js new file mode 100644 index 000000000..5eab6a5fa --- /dev/null +++ b/tests/integration/components/file-version/component-test.js @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('file-version', 'Integration | Component | file version', { + integration: true +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.render(hbs`{{file-version}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#file-version}} + template block text + {{/file-version}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); From 414824c37c5c6cf44707c3ab00aac424ea49bf23 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 12:17:19 -0400 Subject: [PATCH 225/959] Start sketching out pagination behavior [#EOSF-30] [ci skip] --- addon/mixins/paginated-controller.js | 17 +++++++++++++++++ addon/mixins/paginated-route.js | 13 +++++++++++++ tests/unit/mixins/paginated-controller-test.js | 12 ++++++++++++ tests/unit/mixins/paginated-route-test.js | 12 ++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 addon/mixins/paginated-controller.js create mode 100644 addon/mixins/paginated-route.js create mode 100644 tests/unit/mixins/paginated-controller-test.js create mode 100644 tests/unit/mixins/paginated-route-test.js diff --git a/addon/mixins/paginated-controller.js b/addon/mixins/paginated-controller.js new file mode 100644 index 000000000..42dc7de35 --- /dev/null +++ b/addon/mixins/paginated-controller.js @@ -0,0 +1,17 @@ +import Ember from 'ember'; + +export default Ember.Mixin.create({ + queryParams: ['page', 'page_size'], + // TODO: Confirm that setting to null causes server to use its default values + page: null, + page_size: null, + + actions: { + prev() { + console.log('previous'); + }, + next() { + console.log('next'); + } + } +}); diff --git a/addon/mixins/paginated-route.js b/addon/mixins/paginated-route.js new file mode 100644 index 000000000..f71998bbe --- /dev/null +++ b/addon/mixins/paginated-route.js @@ -0,0 +1,13 @@ +import Ember from 'ember'; + +export default Ember.Mixin.create({ + // When page numbers are updated, fetch the new results from the server + queryParams: { + page: { + refreshModel: true + }, + page_size: { + refreshModel: true + } + } +}); diff --git a/tests/unit/mixins/paginated-controller-test.js b/tests/unit/mixins/paginated-controller-test.js new file mode 100644 index 000000000..8ab01a394 --- /dev/null +++ b/tests/unit/mixins/paginated-controller-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import PaginatedControllerMixin from 'ember-osf/mixins/paginated-controller'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | paginated controller'); + +// Replace this with your real tests. +test('it works', function(assert) { + let PaginatedControllerObject = Ember.Object.extend(PaginatedControllerMixin); + let subject = PaginatedControllerObject.create(); + assert.ok(subject); +}); diff --git a/tests/unit/mixins/paginated-route-test.js b/tests/unit/mixins/paginated-route-test.js new file mode 100644 index 000000000..ca4a94774 --- /dev/null +++ b/tests/unit/mixins/paginated-route-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import PaginatedRouteMixin from 'ember-osf/mixins/paginated-route'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | paginated route'); + +// Replace this with your real tests. +test('it works', function(assert) { + let PaginatedRouteObject = Ember.Object.extend(PaginatedRouteMixin); + let subject = PaginatedRouteObject.create(); + assert.ok(subject); +}); From 6fad5e60caaffb4c9c2555bff8c1173e3ba995fe Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 13:02:35 -0400 Subject: [PATCH 226/959] Move users index route to named list route This prevents collection-specific behavior (like URL params) from being used by the child route. Follows pattern used in experimenter routing. [ci skip] --- tests/dummy/app/controllers/users/list.js | 6 ++++++ tests/dummy/app/router.js | 3 +++ tests/dummy/app/routes/{users.js => users/list.js} | 4 +++- tests/dummy/app/templates/users/{index.hbs => list.hbs} | 7 +++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/dummy/app/controllers/users/list.js rename tests/dummy/app/routes/{users.js => users/list.js} (63%) rename tests/dummy/app/templates/users/{index.hbs => list.hbs} (76%) diff --git a/tests/dummy/app/controllers/users/list.js b/tests/dummy/app/controllers/users/list.js new file mode 100644 index 000000000..e6ade450a --- /dev/null +++ b/tests/dummy/app/controllers/users/list.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; + +import PaginatedControllerMixin from 'ember-osf/mixins/paginated-route'; + +export default Ember.Controller.extend(PaginatedControllerMixin, { +}); diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 741aabfe3..c0fcd2a8f 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -26,6 +26,9 @@ Router.map(function() { }); }); this.route('users', function() { + this.route('list', { + path: '/' + }); this.route('detail', { path: '/:user_id' }); diff --git a/tests/dummy/app/routes/users.js b/tests/dummy/app/routes/users/list.js similarity index 63% rename from tests/dummy/app/routes/users.js rename to tests/dummy/app/routes/users/list.js index 15c1636ee..626b66139 100644 --- a/tests/dummy/app/routes/users.js +++ b/tests/dummy/app/routes/users/list.js @@ -1,7 +1,9 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Ember.Route.extend(AuthenticatedRouteMixin, { +import PaginatedRouteMixin from 'ember-osf/mixins/paginated-route'; + +export default Ember.Route.extend(AuthenticatedRouteMixin, PaginatedRouteMixin, { store: Ember.inject.service(), session: Ember.inject.service(), model() { diff --git a/tests/dummy/app/templates/users/index.hbs b/tests/dummy/app/templates/users/list.hbs similarity index 76% rename from tests/dummy/app/templates/users/index.hbs rename to tests/dummy/app/templates/users/list.hbs index 3bda43461..aed31e37e 100644 --- a/tests/dummy/app/templates/users/index.hbs +++ b/tests/dummy/app/templates/users/list.hbs @@ -1,4 +1,11 @@

    Users

    + +Current page: {{page}} + + +Previous: +Next: +
    {{#each model as |user|}}
    From ef83f83d98e0b1901fd9d35c6dd331b03a6c08a7 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 13:26:06 -0400 Subject: [PATCH 227/959] Simple increment/decrement controls [ci skip] --- addon/mixins/paginated-controller.js | 21 ++++++++++++++++----- tests/dummy/app/controllers/users/list.js | 2 +- tests/dummy/app/templates/users/list.hbs | 11 ++++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/addon/mixins/paginated-controller.js b/addon/mixins/paginated-controller.js index 42dc7de35..819830aa8 100644 --- a/addon/mixins/paginated-controller.js +++ b/addon/mixins/paginated-controller.js @@ -3,15 +3,26 @@ import Ember from 'ember'; export default Ember.Mixin.create({ queryParams: ['page', 'page_size'], // TODO: Confirm that setting to null causes server to use its default values - page: null, + page: 1, page_size: null, - + + // Placeholders, may use pagination metadata to track this instead + firstPage: null, + lastPage: null, + actions: { - prev() { - console.log('previous'); + previous() { + // TODO: Add bounds checking somewhere + this.decrementProperty('page', 1); + console.log('decrement to previous'); }, next() { - console.log('next'); + this.incrementProperty('page', 1); + console.log('increment to next'); + }, + goToPage(pageNumber) { + this.set('page', pageNumber); + console.log('Went to page: ', this.get('page')); } } }); diff --git a/tests/dummy/app/controllers/users/list.js b/tests/dummy/app/controllers/users/list.js index e6ade450a..b00e2d053 100644 --- a/tests/dummy/app/controllers/users/list.js +++ b/tests/dummy/app/controllers/users/list.js @@ -1,6 +1,6 @@ import Ember from 'ember'; -import PaginatedControllerMixin from 'ember-osf/mixins/paginated-route'; +import PaginatedControllerMixin from 'ember-osf/mixins/paginated-controller'; export default Ember.Controller.extend(PaginatedControllerMixin, { }); diff --git a/tests/dummy/app/templates/users/list.hbs b/tests/dummy/app/templates/users/list.hbs index aed31e37e..129aac0cb 100644 --- a/tests/dummy/app/templates/users/list.hbs +++ b/tests/dummy/app/templates/users/list.hbs @@ -1,10 +1,11 @@ -

    Users

    +

    Users

    -Current page: {{page}} +

    + Current Page: {{page}} +

    - -Previous: -Next: + +
    {{#each model as |user|}} From 47cd728f3e3a8a6eaf7aed401d9ed6d2bf735d62 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Thu, 19 May 2016 13:42:15 -0400 Subject: [PATCH 228/959] clean up updateRecord --- addon/adapters/node.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 033e6a088..873e1eae6 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -26,20 +26,12 @@ export default OsfAdapter.extend({ } }, updateRecord(store, type, snapshot) { - var self = this; - if (isEnabled('ds-improved-ajax')) { - return this._super(...arguments); + var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord'); + if (url.indexOf('relationships') !== -1){ + data = self.relationshipPayload(snapshot, url); + return this.ajax(url, 'PATCH', { data: data }); } else { - var data = {}; - var id = snapshot.id; - var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord'); - if (url.indexOf('relationships') !== -1){ - data = self.relationshipPayload(snapshot, url); - } else { - var serializer = store.serializerFor(type.modelName); - serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); - } - return this.ajax(url, 'PATCH', { data: data }); + return this._super(...arguments); } } }); From 5cda9e106e427600d33cdc8af4728f92f310c023 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 14:37:12 -0400 Subject: [PATCH 229/959] Fetching params via controller- freeze an experiment Save this as an experiment, but page_size isn't correctly being fetched from the controller on initial page load (though it is after clicking next or prev at least once) So instead use model hook params [ci skip] --- addon/mixins/paginated-route.js | 22 ++++++++++++++++++++++ tests/dummy/app/routes/users/list.js | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/addon/mixins/paginated-route.js b/addon/mixins/paginated-route.js index f71998bbe..345302056 100644 --- a/addon/mixins/paginated-route.js +++ b/addon/mixins/paginated-route.js @@ -9,5 +9,27 @@ export default Ember.Mixin.create({ page_size: { refreshModel: true } + }, + + /* + Convenience method. Given a model name (and optional user params), fetch a page of records. + */ + queryForPage(modelName, routeParams, userParams) { + // TODO: While it would be a nicer API to fetch params from the controller directly, page_size wasn't correctly being initialized + + let controller = this.controllerFor(this.routeName); + + let defaultParams = {page: controller.get('page')}; + let pageSize = controller.get('page_size'); + + if (pageSize) { + // TODO: if the user manually passes params, + defaultParams['page[size]'] = pageSize; + } + + let params = Object.assign({}, userParams || {}, defaultParams); + console.log('qparam', params); + + //return this.store.query(modelName, params); } }); diff --git a/tests/dummy/app/routes/users/list.js b/tests/dummy/app/routes/users/list.js index 626b66139..0bfbc6896 100644 --- a/tests/dummy/app/routes/users/list.js +++ b/tests/dummy/app/routes/users/list.js @@ -6,7 +6,8 @@ import PaginatedRouteMixin from 'ember-osf/mixins/paginated-route'; export default Ember.Route.extend(AuthenticatedRouteMixin, PaginatedRouteMixin, { store: Ember.inject.service(), session: Ember.inject.service(), - model() { + model(params) { + this.queryForPage('user'); return this.get('store').findAll('user'); } }); From 7a9e50d912eb9588f45b38fe4bd555c429a3d15f Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 19 May 2016 14:51:44 -0400 Subject: [PATCH 230/959] Fix failing test --- addon/components/file-version/template.hbs | 6 +++--- .../components/file-version/component-test.js | 14 +++----------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/addon/components/file-version/template.hbs b/addon/components/file-version/template.hbs index 92b58285b..28127f04b 100644 --- a/addon/components/file-version/template.hbs +++ b/addon/components/file-version/template.hbs @@ -1,6 +1,6 @@
  • -
    {{model.id}}
    -
    {{model.size}}
    -
    {{model.contentType}}
    +
    {{model.id}}
    +
    {{model.size}}
    +
    {{model.contentType}}
  • {{yield}} diff --git a/tests/integration/components/file-version/component-test.js b/tests/integration/components/file-version/component-test.js index 5eab6a5fa..04b2f9499 100644 --- a/tests/integration/components/file-version/component-test.js +++ b/tests/integration/components/file-version/component-test.js @@ -8,17 +8,9 @@ moduleForComponent('file-version', 'Integration | Component | file version', { test('it renders', function(assert) { // Set any properties with this.set('myProperty', 'value'); // Handle any actions with this.on('myAction', function(val) { ... }); + this.set('version', {'id': '1', 'size': 125, 'contentType': 'text'}); + this.render(hbs`{{file-version model=version}}`); - this.render(hbs`{{file-version}}`); + assert.equal(this.$().text().trim(), 'ID: 1\n Size: 125\n Content type: text'); - assert.equal(this.$().text().trim(), ''); - - // Template block usage: - this.render(hbs` - {{#file-version}} - template block text - {{/file-version}} - `); - - assert.equal(this.$().text().trim(), 'template block text'); }); From 6cb051b09b52ca753f6dbec0bd408649b36f5ed7 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 19 May 2016 14:59:43 -0400 Subject: [PATCH 231/959] Fix indentation errors --- addon/components/sign-up/template.hbs | 18 +++++++++--------- tests/dummy/app/templates/signup.hbs | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/addon/components/sign-up/template.hbs b/addon/components/sign-up/template.hbs index 03d793f6c..adf81e79f 100644 --- a/addon/components/sign-up/template.hbs +++ b/addon/components/sign-up/template.hbs @@ -45,16 +45,16 @@ placeholder="Password" >
    - -
    -

    By clicking "Create account", you agree to our Terms and that you have read our Privacy Policy, including our information on Cookie Use.

    -
    -
    -
    - -
    +
    +
    +

    By clicking "Create account", you agree to our Terms and that you have read our Privacy Policy, including our information on Cookie Use.

    +
    +
    +
    +
    +
    - +

    {{yield}}

    diff --git a/tests/dummy/app/templates/signup.hbs b/tests/dummy/app/templates/signup.hbs index 2440f36a7..47d12fd68 100644 --- a/tests/dummy/app/templates/signup.hbs +++ b/tests/dummy/app/templates/signup.hbs @@ -1,8 +1,8 @@
    -
    - {{#login-form}}{{/login-form}} -
    -
    - {{#sign-up}}{{/sign-up}} -
    +
    + {{#login-form}}{{/login-form}} +
    +
    + {{#sign-up}}{{/sign-up}} +
    \ No newline at end of file From ceabdaf244ffee562ff0675861e531755dcb9a8f Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 19 May 2016 15:24:08 -0400 Subject: [PATCH 232/959] Getting Node.institution adding working - Allow custom serializers to be passed into DS.attr options hash - Defer to API provided link for updateRecord on relationships --- addon/adapters/node.js | 31 ++-------- addon/adapters/osf-adapter.js | 66 ++++++++++++++------- addon/mixins/osf-model.js | 30 +++++++--- addon/models/node.js | 5 +- addon/serializers/relationship.js | 11 ++++ app/serializers/relationship.js | 1 + tests/dummy/app/routes/nodes/detail.js | 6 +- tests/dummy/app/templates/nodes/detail.hbs | 1 + tests/unit/serializers/relationship-test.js | 15 +++++ 9 files changed, 106 insertions(+), 60 deletions(-) create mode 100644 addon/serializers/relationship.js create mode 100644 app/serializers/relationship.js create mode 100644 tests/unit/serializers/relationship-test.js diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 873e1eae6..7c283245c 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -5,33 +5,12 @@ import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ buildURL(_, __, snapshot, requestType) { - var self = this; - if (requestType === 'updateRecord' && !snapshot.record.changedAttributes().length) { - var urls = self.findDirtyRelations(snapshot).map((rel) => { - var links = snapshot.record.get( - `links.relationships.${Ember.String.underscore(rel)}.links` - ); - return links.self ? links.self.href : links.related.href; - }); - this.customSerialize = {}; - return urls[0]; + // Embed contributors + var base = this._super(...arguments); + if (['createRecord', 'updateRecord', 'deleteRecord'].indexOf(requestType) === -1) { + return `${base}?embed=contributors`; } else { - // Embed contributors - var base = this._super(...arguments); - if (['createRecord', 'updateRecord', 'deleteRecord'].indexOf(requestType) === -1) { - return `${base}?embed=contributors`; - } else { - return base; - } + return base; } - }, - updateRecord(store, type, snapshot) { - var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord'); - if (url.indexOf('relationships') !== -1){ - data = self.relationshipPayload(snapshot, url); - return this.ajax(url, 'PATCH', { data: data }); - } else { - return this._super(...arguments); - } } }); diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index 406b29ef0..cc796a453 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -1,6 +1,7 @@ /* Base adapter class for all OSF APIv2 endpoints */ +import Ember from 'ember'; import DS from 'ember-data'; import config from 'ember-get-config'; @@ -11,30 +12,49 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { host: config.OSF.apiUrl, namespace: config.OSF.apiNamespace, - buildURL(modelName, id, snapshot, requestType, query) { // jshint ignore:line - var url = this._super(...arguments); - // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing - // slash to URLs for single documents, but DRF redirects to force a trailing slash - if (url.lastIndexOf('/') !== 0) { - url += '/'; + buildURL(modelName, id, snapshot, requestType, query) { // jshint ignore:line + if (requestType === 'updateRecord' && !snapshot.record.changedAttributes().length) { + var urls = snapshot.record.get('dirtyRelationships').map((rel) => { + var links = snapshot.record.get( + `links.relationships.${Ember.String.underscore(rel)}.links` + ); + return links.self ? links.self.href : links.related.href; + }); + return urls[0]; + } else { + var url = this._super(...arguments); + // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing + // slash to URLs for single documents, but DRF redirects to force a trailing slash + if (url.lastIndexOf('/') !== 0) { + url += '/'; + } + return url; } - return url; }, - findDirtyRelations(snapshot) { - var dirtyRelationships = snapshot.record.get('dirtyRelationships'); - return Object.keys(dirtyRelationships).filter(function(rel){ - var attr = snapshot._internalModel._relationships.get(rel); - var foo = Ember.get(dirtyRelationships, rel); - return attr && foo && Ember.get(attr.relationshipMeta.options, 'relationshipEndpoint'); - }); - }, - relationshipPayload(snapshot, url){ - var dirty = this.findDirtyRelations(snapshot)[0]; - var url_ = url.split('/'); - var relationType = url_[url_.indexOf('relationships') + 1]; - var dirtyList = snapshot._internalModel._relationships.get(dirty).members.list; - return {data: dirtyList.map(function(item){ - return {type: relationType, id: item.id} - })} + relationshipPayload(snapshot, dirty, store) { + var relationMeta = snapshot.record[dirty].meta(); + var relationType = relationMeta.type; + var Serializer = relationMeta.options.serializer || store.serializerFor( + relationType + ); + var serializer = new Serializer(); + return { + data: snapshot.record.get(dirty).map((record) => { + return serializer.serialize(new DS.Snapshot(record._internalModel)); + }) + }; }, + updateRecord(store, type, snapshot) { + var dirtyRelationships = snapshot.record.get('dirtyRelationships'); + if (dirtyRelationships.length) { + var dirty = dirtyRelationships[0]; + var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord', dirty); + return this.ajax(url, 'PATCH', { + data: this.relationshipPayload(snapshot, dirty, store) + }); + + } else { + return this._super(...arguments); + } + } }); diff --git a/addon/mixins/osf-model.js b/addon/mixins/osf-model.js index 1fc058fc5..83d18850a 100644 --- a/addon/mixins/osf-model.js +++ b/addon/mixins/osf-model.js @@ -10,17 +10,29 @@ export default Ember.Mixin.create({ embeds: DS.attr('embed'), relationshipLinks: DS.attr('links'), - dirtyRelationships: {}, + dirtyRelationships: Ember.computed('_dirtyRelationships', function() { + var dirtyRelationships = this.get('_dirtyRelationships'); + return Object.keys(dirtyRelationships).map((rel) => { + if (rel === 'files') { + return null; + } + if (dirtyRelationships[rel]) { + return rel; + } + return null; + }).filter(Boolean); + }), + _dirtyRelationships: {}, onLoad: Ember.on('ready', function() { - this.eachRelationship((rel) => { + this.eachRelationship((rel) => { let update = function() { - let key = `dirtyRelationships.${rel}`; - this.set(key, !Ember.isEmpty(this.get(key))); - }.bind(this); + let key = `_dirtyRelationships.${rel}`; + this.set(key, !Ember.isEmpty(this.get(key))); + }.bind(this); - this.get(rel).then(() => { - this.addObserver(rel, update); - }); - }); + this.get(rel).then(() => { + this.addObserver(rel, update); + }); + }); }) }); diff --git a/addon/models/node.js b/addon/models/node.js index 6673eae43..8bd57fbb9 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -1,6 +1,7 @@ import DS from 'ember-data'; import OsfModel from '../mixins/osf-model'; +import RelationshipSerializer from '../serializers/relationship'; export default DS.Model.extend(OsfModel, { title: DS.attr('string'), @@ -29,7 +30,9 @@ export default DS.Model.extend(OsfModel, { }), affiliatedInstitutions: DS.hasMany('institutions', { inverse: 'nodes', - relationshipEndpoint: true + serializer: RelationshipSerializer.extend({ + type: 'institutions' + }) }), comments: DS.hasMany('comments'), contributors: DS.hasMany('contributors'), diff --git a/addon/serializers/relationship.js b/addon/serializers/relationship.js new file mode 100644 index 000000000..cf9d6eb68 --- /dev/null +++ b/addon/serializers/relationship.js @@ -0,0 +1,11 @@ +import Serializer from 'ember-data/serializers/json-api'; + +export default Serializer.extend({ + type: null, + serialize: function(snapshot) { + return { + type: this.get('type'), + id: snapshot.record.get('id') + }; + } +}); diff --git a/app/serializers/relationship.js b/app/serializers/relationship.js new file mode 100644 index 000000000..68fb4e4b1 --- /dev/null +++ b/app/serializers/relationship.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/serializers/relationship'; diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 3a5b31679..2a48aad19 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -32,6 +32,10 @@ export default Ember.Route.extend({ } ); }, + deaffiliateNode(inst) { + var node = this.modelFor(this.routeName); + node.get('affiliatedInstitutions').removeObject(inst); + node.save(); + } } - }); diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 62a988595..edab779ac 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -39,6 +39,7 @@
    {{inst.name}} + {{/each}}

    diff --git a/tests/unit/serializers/relationship-test.js b/tests/unit/serializers/relationship-test.js new file mode 100644 index 000000000..09349ab46 --- /dev/null +++ b/tests/unit/serializers/relationship-test.js @@ -0,0 +1,15 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('relationship', 'Unit | Serializer | relationship', { + // Specify the other units that are required for this test. + needs: ['serializer:relationship'] +}); + +// Replace this with your real tests. +test('it serializes records', function(assert) { + let record = this.subject(); + + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); From d871febfa35eb47bc5110947eca9fabbead5f46e Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 19 May 2016 15:28:24 -0400 Subject: [PATCH 233/959] Fix failing tests --- addon/components/sign-up/template.hbs | 2 +- .../components/login-form/component-test.js | 14 +++++--------- .../components/sign-up/component-test.js | 17 ++++++++--------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/addon/components/sign-up/template.hbs b/addon/components/sign-up/template.hbs index adf81e79f..7247ede0c 100644 --- a/addon/components/sign-up/template.hbs +++ b/addon/components/sign-up/template.hbs @@ -3,7 +3,7 @@

    Create a free account

    - +
    Date: Thu, 19 May 2016 15:31:41 -0400 Subject: [PATCH 234/959] move updateRecord around --- addon/adapters/node.js | 10 ---------- addon/adapters/osf-adapter.js | 9 +++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 873e1eae6..30274d569 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -13,7 +13,6 @@ export default OsfAdapter.extend({ ); return links.self ? links.self.href : links.related.href; }); - this.customSerialize = {}; return urls[0]; } else { // Embed contributors @@ -24,14 +23,5 @@ export default OsfAdapter.extend({ return base; } } - }, - updateRecord(store, type, snapshot) { - var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord'); - if (url.indexOf('relationships') !== -1){ - data = self.relationshipPayload(snapshot, url); - return this.ajax(url, 'PATCH', { data: data }); - } else { - return this._super(...arguments); - } } }); diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index 406b29ef0..09c160d6b 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -37,4 +37,13 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { return {type: relationType, id: item.id} })} }, + updateRecord(store, type, snapshot) { + var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord'); + if (url.indexOf('relationships') !== -1){ + data = self.relationshipPayload(snapshot, url); + return this.ajax(url, 'PATCH', { data: data }); + } else { + return this._super(...arguments); + } + } }); From 68c10b409615eb7e15e6501a515e5866224e10b0 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 15:32:16 -0400 Subject: [PATCH 235/959] Get users page to use the pagination mixin [ci skip] --- addon/mixins/paginated-route.js | 31 ++++++++++++---------------- tests/dummy/app/routes/users/list.js | 5 ++--- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/addon/mixins/paginated-route.js b/addon/mixins/paginated-route.js index 345302056..57ed66173 100644 --- a/addon/mixins/paginated-route.js +++ b/addon/mixins/paginated-route.js @@ -11,25 +11,20 @@ export default Ember.Mixin.create({ } }, - /* - Convenience method. Given a model name (and optional user params), fetch a page of records. - */ - queryForPage(modelName, routeParams, userParams) { - // TODO: While it would be a nicer API to fetch params from the controller directly, page_size wasn't correctly being initialized - - let controller = this.controllerFor(this.routeName); + // Allow support for different APIs, by making the API pagination query param names configurable. Most users will not need to change this. + // TODO: Use these + pageArg: 'page', + pageSizeArg: 'page[size]', - let defaultParams = {page: controller.get('page')}; - let pageSize = controller.get('page_size'); - - if (pageSize) { - // TODO: if the user manually passes params, - defaultParams['page[size]'] = pageSize; + /* Convenience method. Given a model name (and optional user params), fetch a page of records. */ + queryForPage(modelName, routeParams, userParams) { + let params = Object.assign({}, userParams || {}, routeParams); + // If page_size is present, rename the url arg to to whatever URL param name the API server expects + if (params.page_size) { + // TODO: support making api pagination param names configurable + params['page[size]'] = params.page_size; } - - let params = Object.assign({}, userParams || {}, defaultParams); - console.log('qparam', params); - - //return this.store.query(modelName, params); + delete params.page_size; + return this.store.query(modelName, params); } }); diff --git a/tests/dummy/app/routes/users/list.js b/tests/dummy/app/routes/users/list.js index 0bfbc6896..a5ece6bfc 100644 --- a/tests/dummy/app/routes/users/list.js +++ b/tests/dummy/app/routes/users/list.js @@ -6,8 +6,7 @@ import PaginatedRouteMixin from 'ember-osf/mixins/paginated-route'; export default Ember.Route.extend(AuthenticatedRouteMixin, PaginatedRouteMixin, { store: Ember.inject.service(), session: Ember.inject.service(), - model(params) { - this.queryForPage('user'); - return this.get('store').findAll('user'); + model(routeParams) { + return this.queryForPage('user', routeParams); } }); From 8858e3877bdef42b9d245f60e63a198a6c6b2e8b Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 19 May 2016 16:27:15 -0400 Subject: [PATCH 236/959] WIP relationship deletes (via PATCH) --- addon/adapters/node.js | 3 --- addon/adapters/osf-adapter.js | 50 +++++++++++++++++------------------ addon/mixins/osf-model.js | 22 ++++++++------- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 7c283245c..66a17c41f 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -1,6 +1,3 @@ -import Ember from 'ember'; -import isEnabled from 'ember-data/-private/features'; - import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index cc796a453..60e53ff23 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -12,15 +12,15 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { host: config.OSF.apiUrl, namespace: config.OSF.apiNamespace, - buildURL(modelName, id, snapshot, requestType, query) { // jshint ignore:line - if (requestType === 'updateRecord' && !snapshot.record.changedAttributes().length) { - var urls = snapshot.record.get('dirtyRelationships').map((rel) => { - var links = snapshot.record.get( - `links.relationships.${Ember.String.underscore(rel)}.links` - ); - return links.self ? links.self.href : links.related.href; - }); - return urls[0]; + buildURL(modelName, id, snapshot, requestType, query, dirtyRelationship) { // jshint ignore:line + if (dirtyRelationship) { + var links = snapshot.record.get( + `links.relationships.${Ember.String.underscore(dirtyRelationship)}.links` + ); + if (links) { + return links.self ? links.self.href : links.related.href; + } + return null; } else { var url = this._super(...arguments); // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing @@ -32,29 +32,29 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { } }, relationshipPayload(snapshot, dirty, store) { - var relationMeta = snapshot.record[dirty].meta(); - var relationType = relationMeta.type; - var Serializer = relationMeta.options.serializer || store.serializerFor( - relationType - ); - var serializer = new Serializer(); + var relationMeta = snapshot.record[dirty].meta(); + var relationType = relationMeta.type; + var Serializer = relationMeta.options.serializer || store.serializerFor( + relationType + ); + var serializer = new Serializer(); return { data: snapshot.record.get(dirty).map((record) => { - return serializer.serialize(new DS.Snapshot(record._internalModel)); - }) + return serializer.serialize(new DS.Snapshot(record._internalModel)); + }) }; }, - updateRecord(store, type, snapshot) { - var dirtyRelationships = snapshot.record.get('dirtyRelationships'); - if (dirtyRelationships.length) { - var dirty = dirtyRelationships[0]; - var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord', dirty); - return this.ajax(url, 'PATCH', { + updateRecord(store, type, snapshot, _, query) { + var dirtyRelationships = snapshot.record.get('dirtyRelationships'); + if (dirtyRelationships.length) { + var dirty = dirtyRelationships.pop(); + var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord', query, dirty); + return this.ajax(url, 'PATCH', { data: this.relationshipPayload(snapshot, dirty, store) }); - } else { + } else { return this._super(...arguments); - } + } } }); diff --git a/addon/mixins/osf-model.js b/addon/mixins/osf-model.js index 83d18850a..a028e3242 100644 --- a/addon/mixins/osf-model.js +++ b/addon/mixins/osf-model.js @@ -11,26 +11,30 @@ export default Ember.Mixin.create({ relationshipLinks: DS.attr('links'), dirtyRelationships: Ember.computed('_dirtyRelationships', function() { - var dirtyRelationships = this.get('_dirtyRelationships'); + var dirtyRelationships = this.get('_dirtyRelationships'); return Object.keys(dirtyRelationships).map((rel) => { - if (rel === 'files') { - return null; - } - if (dirtyRelationships[rel]) { - return rel; - } - return null; + if (rel === 'files') { + return null; + } + if (dirtyRelationships[rel]) { + return rel; + } + return null; }).filter(Boolean); }), _dirtyRelationships: {}, onLoad: Ember.on('ready', function() { - this.eachRelationship((rel) => { + this.eachRelationship((rel, meta) => { let update = function() { let key = `_dirtyRelationships.${rel}`; this.set(key, !Ember.isEmpty(this.get(key))); }.bind(this); this.get(rel).then(() => { + var watch = rel; + if (meta.kind === 'hasMany') { + watch = `${rel}.[]`; + } this.addObserver(rel, update); }); }); From 07155345557ad70ba3452da34beba31d45ceda92 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 19 May 2016 16:34:46 -0400 Subject: [PATCH 237/959] Add render urls to config. --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 13538ab5e..3b3ac7419 100644 --- a/index.js +++ b/index.js @@ -28,6 +28,7 @@ module.exports = { ENV.OSF.url = 'http://localhost:5000/'; ENV.OSF.apiUrl = 'http://localhost:8000'; ENV.OSF.authUrl = 'http://localhost:8080/oauth2/profile'; + ENV.OSF.renderUrl = 'http://localhost:7778/render'; ENV.OSF.accessToken = SETTINGS.PERSONAL_ACCESS_TOKEN; ENV.OSF.isLocal = true; @@ -36,22 +37,26 @@ module.exports = { ENV.OSF.url = 'https://staging.osf.io/'; ENV.OSF.apiUrl = 'https://staging-api.osf.io'; ENV.OSF.authUrl = 'https://staging-accounts.osf.io/oauth2/authorize'; + ENV.OSF.renderUrl = 'http://staging-mfr.osf.io/render'; } if (BACKEND === 'stage2') { ENV.OSF.url = 'https://staging2.osf.io/'; ENV.OSF.apiUrl = 'https://staging2-api.osf.io'; ENV.OSF.authUrl = 'https://staging2-accounts.osf.io/oauth2/authorize'; + ENV.OSF.renderUrl = 'http://staging2-mfr.osf.io/render'; } if (BACKEND === 'test') { ENV.OSF.url = 'https://test.osf.io/'; ENV.OSF.apiUrl = 'https://test-api.osf.io'; ENV.OSF.authUrl = 'https://test-accounts.osf.io/oauth2/authorize'; + ENV.OSF.renderUrl = 'http://test-mfr.osf.io/render'; } if (BACKEND === 'prod') { console.log(`WARNING: you\'ve specified production as a backend. Please do not use production for testing or development purposes`); ENV.OSF.url = 'https://osf.io/'; ENV.OSF.apiUrl = 'https://api.osf.io'; ENV.OSF.authUrl = 'https://accounts.osf.io/oauth2/authorize'; + ENV.OSF.renderUrl = 'http://mfr.osf.io/render'; } ENV['ember-simple-auth'] = { authorizer: 'authorizer:osf-token' From 5fec33458c65b63016e462bbbcfa678b228e9d4a Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 19 May 2016 16:36:14 -0400 Subject: [PATCH 238/959] Add file-renderer component. --- addon/components/file-renderer/component.js | 6 +++++ addon/components/file-renderer/template.hbs | 0 app/components/file-renderer/component.js | 1 + .../file-renderer/component-test.js | 24 +++++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 addon/components/file-renderer/component.js create mode 100644 addon/components/file-renderer/template.hbs create mode 100644 app/components/file-renderer/component.js create mode 100644 tests/integration/components/file-renderer/component-test.js diff --git a/addon/components/file-renderer/component.js b/addon/components/file-renderer/component.js new file mode 100644 index 000000000..44bf16cc0 --- /dev/null +++ b/addon/components/file-renderer/component.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; +import layout from './template'; + +export default Ember.Component.extend({ + layout +}); diff --git a/addon/components/file-renderer/template.hbs b/addon/components/file-renderer/template.hbs new file mode 100644 index 000000000..e69de29bb diff --git a/app/components/file-renderer/component.js b/app/components/file-renderer/component.js new file mode 100644 index 000000000..057d531da --- /dev/null +++ b/app/components/file-renderer/component.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/file-renderer/component'; diff --git a/tests/integration/components/file-renderer/component-test.js b/tests/integration/components/file-renderer/component-test.js new file mode 100644 index 000000000..53a8cd78b --- /dev/null +++ b/tests/integration/components/file-renderer/component-test.js @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('file-renderer', 'Integration | Component | file renderer', { + integration: true +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.render(hbs`{{file-renderer}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#file-renderer}} + template block text + {{/file-renderer}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); From f0cfea4896cdf1e66251feb909276a6d00f946ed Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 19 May 2016 16:37:05 -0400 Subject: [PATCH 239/959] Add helper that creates the url to send to MFR. --- addon/helpers/build-mfr-url.js | 12 ++++++++++++ app/helpers/build-mfr-url.js | 1 + tests/unit/helpers/build-mfr-url-test.js | 10 ++++++++++ 3 files changed, 23 insertions(+) create mode 100644 addon/helpers/build-mfr-url.js create mode 100644 app/helpers/build-mfr-url.js create mode 100644 tests/unit/helpers/build-mfr-url-test.js diff --git a/addon/helpers/build-mfr-url.js b/addon/helpers/build-mfr-url.js new file mode 100644 index 000000000..683ae1cbf --- /dev/null +++ b/addon/helpers/build-mfr-url.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import config from 'ember-get-config'; + +export function buildMfrUrl(params/*, hash*/) { + var base = config.OSF.renderUrl; + var download = params[0]; + var renderUrl = base + '?url=' + download; + // return renderUrl; + return 'http://localhost:7778/render?url=http://localhost:5000/zps63/?action=download%26direct%26mode=render&initialWidth=766&childId=mfrIframe'; +} + +export default Ember.Helper.helper(buildMfrUrl); diff --git a/app/helpers/build-mfr-url.js b/app/helpers/build-mfr-url.js new file mode 100644 index 000000000..de1b939a3 --- /dev/null +++ b/app/helpers/build-mfr-url.js @@ -0,0 +1 @@ +export { default, buildMfrUrl } from 'ember-osf/helpers/build-mfr-url'; diff --git a/tests/unit/helpers/build-mfr-url-test.js b/tests/unit/helpers/build-mfr-url-test.js new file mode 100644 index 000000000..f14eff57d --- /dev/null +++ b/tests/unit/helpers/build-mfr-url-test.js @@ -0,0 +1,10 @@ +import { buildMfrUrl } from 'dummy/helpers/build-mfr-url'; +import { module, test } from 'qunit'; + +module('Unit | Helper | build mfr url'); + +// Replace this with your real tests. +test('it works', function(assert) { + let result = buildMfrUrl([42]); + assert.ok(result); +}); From 4042fababf50e4ca8803b04438a821b966d9f898 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 19 May 2016 16:37:33 -0400 Subject: [PATCH 240/959] Add iframe to file-renderer template. --- addon/components/file-renderer/template.hbs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addon/components/file-renderer/template.hbs b/addon/components/file-renderer/template.hbs index e69de29bb..844dbccd3 100644 --- a/addon/components/file-renderer/template.hbs +++ b/addon/components/file-renderer/template.hbs @@ -0,0 +1,2 @@ + From 6e2824f41118b90fb5fe81e33281ac3627e04026 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Thu, 19 May 2016 16:38:45 -0400 Subject: [PATCH 241/959] Use the file-renderer component inside the file detail template. --- tests/dummy/app/templates/file.hbs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs index ed7cafa03..e9217be0a 100644 --- a/tests/dummy/app/templates/file.hbs +++ b/tests/dummy/app/templates/file.hbs @@ -1,5 +1,5 @@
    -

    File detail

    +

    File detail

    Download

    {{model.name}}

    {{model.kind}}

    {{model.path}}

    @@ -34,5 +34,9 @@ {{else}} (none) {{/each}} - + + +
    + {{#file-renderer download=model.links.download}} + {{/file-renderer}}
    From 9b69f3b63d001036bd90bd9143fb9fae2248d5d0 Mon Sep 17 00:00:00 2001 From: Henrique Harman Date: Thu, 19 May 2016 16:40:35 -0400 Subject: [PATCH 242/959] Revert "WIP relationship deletes (via PATCH)" --- addon/adapters/node.js | 3 +++ addon/adapters/osf-adapter.js | 50 +++++++++++++++++------------------ addon/mixins/osf-model.js | 22 +++++++-------- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 66a17c41f..7c283245c 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -1,3 +1,6 @@ +import Ember from 'ember'; +import isEnabled from 'ember-data/-private/features'; + import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index 60e53ff23..cc796a453 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -12,15 +12,15 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { host: config.OSF.apiUrl, namespace: config.OSF.apiNamespace, - buildURL(modelName, id, snapshot, requestType, query, dirtyRelationship) { // jshint ignore:line - if (dirtyRelationship) { - var links = snapshot.record.get( - `links.relationships.${Ember.String.underscore(dirtyRelationship)}.links` - ); - if (links) { - return links.self ? links.self.href : links.related.href; - } - return null; + buildURL(modelName, id, snapshot, requestType, query) { // jshint ignore:line + if (requestType === 'updateRecord' && !snapshot.record.changedAttributes().length) { + var urls = snapshot.record.get('dirtyRelationships').map((rel) => { + var links = snapshot.record.get( + `links.relationships.${Ember.String.underscore(rel)}.links` + ); + return links.self ? links.self.href : links.related.href; + }); + return urls[0]; } else { var url = this._super(...arguments); // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing @@ -32,29 +32,29 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { } }, relationshipPayload(snapshot, dirty, store) { - var relationMeta = snapshot.record[dirty].meta(); - var relationType = relationMeta.type; - var Serializer = relationMeta.options.serializer || store.serializerFor( - relationType - ); - var serializer = new Serializer(); + var relationMeta = snapshot.record[dirty].meta(); + var relationType = relationMeta.type; + var Serializer = relationMeta.options.serializer || store.serializerFor( + relationType + ); + var serializer = new Serializer(); return { data: snapshot.record.get(dirty).map((record) => { - return serializer.serialize(new DS.Snapshot(record._internalModel)); - }) + return serializer.serialize(new DS.Snapshot(record._internalModel)); + }) }; }, - updateRecord(store, type, snapshot, _, query) { - var dirtyRelationships = snapshot.record.get('dirtyRelationships'); - if (dirtyRelationships.length) { - var dirty = dirtyRelationships.pop(); - var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord', query, dirty); - return this.ajax(url, 'PATCH', { + updateRecord(store, type, snapshot) { + var dirtyRelationships = snapshot.record.get('dirtyRelationships'); + if (dirtyRelationships.length) { + var dirty = dirtyRelationships[0]; + var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord', dirty); + return this.ajax(url, 'PATCH', { data: this.relationshipPayload(snapshot, dirty, store) }); - } else { + } else { return this._super(...arguments); - } + } } }); diff --git a/addon/mixins/osf-model.js b/addon/mixins/osf-model.js index a028e3242..83d18850a 100644 --- a/addon/mixins/osf-model.js +++ b/addon/mixins/osf-model.js @@ -11,30 +11,26 @@ export default Ember.Mixin.create({ relationshipLinks: DS.attr('links'), dirtyRelationships: Ember.computed('_dirtyRelationships', function() { - var dirtyRelationships = this.get('_dirtyRelationships'); + var dirtyRelationships = this.get('_dirtyRelationships'); return Object.keys(dirtyRelationships).map((rel) => { - if (rel === 'files') { - return null; - } - if (dirtyRelationships[rel]) { - return rel; - } - return null; + if (rel === 'files') { + return null; + } + if (dirtyRelationships[rel]) { + return rel; + } + return null; }).filter(Boolean); }), _dirtyRelationships: {}, onLoad: Ember.on('ready', function() { - this.eachRelationship((rel, meta) => { + this.eachRelationship((rel) => { let update = function() { let key = `_dirtyRelationships.${rel}`; this.set(key, !Ember.isEmpty(this.get(key))); }.bind(this); this.get(rel).then(() => { - var watch = rel; - if (meta.kind === 'hasMany') { - watch = `${rel}.[]`; - } this.addObserver(rel, update); }); }); From 6b7d8b300568b50858c0766a31b7451049ec857b Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Thu, 19 May 2016 16:47:41 -0400 Subject: [PATCH 243/959] Add log-adapter --- addon/adapters/log.js | 3 +++ addon/adapters/osf-adapter.js | 18 +++++++++--------- app/adapters/log.js | 1 + tests/unit/adapters/log-test.js | 12 ++++++++++++ 4 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 addon/adapters/log.js create mode 100644 app/adapters/log.js create mode 100644 tests/unit/adapters/log-test.js diff --git a/addon/adapters/log.js b/addon/adapters/log.js new file mode 100644 index 000000000..f9d075992 --- /dev/null +++ b/addon/adapters/log.js @@ -0,0 +1,3 @@ +import OsfAdapter from './osf-adapter'; + +export default OsfAdapter.extend({}); diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index 60e53ff23..6a026f509 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -13,23 +13,23 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { namespace: config.OSF.apiNamespace, buildURL(modelName, id, snapshot, requestType, query, dirtyRelationship) { // jshint ignore:line + var url; if (dirtyRelationship) { var links = snapshot.record.get( `links.relationships.${Ember.String.underscore(dirtyRelationship)}.links` ); if (links) { - return links.self ? links.self.href : links.related.href; + url = links.self ? links.self.href : links.related.href; } - return null; } else { - var url = this._super(...arguments); - // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing - // slash to URLs for single documents, but DRF redirects to force a trailing slash - if (url.lastIndexOf('/') !== 0) { - url += '/'; - } - return url; + url = this._super(...arguments); + } + // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing + // slash to URLs for single documents, but DRF redirects to force a trailing slash + if (url.lastIndexOf('/') !== 0) { + url += '/'; } + return url; }, relationshipPayload(snapshot, dirty, store) { var relationMeta = snapshot.record[dirty].meta(); diff --git a/app/adapters/log.js b/app/adapters/log.js new file mode 100644 index 000000000..1abf93540 --- /dev/null +++ b/app/adapters/log.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/adapters/log'; diff --git a/tests/unit/adapters/log-test.js b/tests/unit/adapters/log-test.js new file mode 100644 index 000000000..f5516f07b --- /dev/null +++ b/tests/unit/adapters/log-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:log', 'Unit | Adapter | log', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let adapter = this.subject(); + assert.ok(adapter); +}); From 46f18bb704244f9b3a8daba8c27245d6b09d8dff Mon Sep 17 00:00:00 2001 From: Henrique Harman Date: Thu, 19 May 2016 16:49:05 -0400 Subject: [PATCH 244/959] Revert "Revert "WIP relationship deletes (via PATCH)"" --- addon/adapters/node.js | 3 --- addon/adapters/osf-adapter.js | 50 +++++++++++++++++------------------ addon/mixins/osf-model.js | 22 ++++++++------- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 7c283245c..66a17c41f 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -1,6 +1,3 @@ -import Ember from 'ember'; -import isEnabled from 'ember-data/-private/features'; - import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index cc796a453..60e53ff23 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -12,15 +12,15 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { host: config.OSF.apiUrl, namespace: config.OSF.apiNamespace, - buildURL(modelName, id, snapshot, requestType, query) { // jshint ignore:line - if (requestType === 'updateRecord' && !snapshot.record.changedAttributes().length) { - var urls = snapshot.record.get('dirtyRelationships').map((rel) => { - var links = snapshot.record.get( - `links.relationships.${Ember.String.underscore(rel)}.links` - ); - return links.self ? links.self.href : links.related.href; - }); - return urls[0]; + buildURL(modelName, id, snapshot, requestType, query, dirtyRelationship) { // jshint ignore:line + if (dirtyRelationship) { + var links = snapshot.record.get( + `links.relationships.${Ember.String.underscore(dirtyRelationship)}.links` + ); + if (links) { + return links.self ? links.self.href : links.related.href; + } + return null; } else { var url = this._super(...arguments); // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing @@ -32,29 +32,29 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { } }, relationshipPayload(snapshot, dirty, store) { - var relationMeta = snapshot.record[dirty].meta(); - var relationType = relationMeta.type; - var Serializer = relationMeta.options.serializer || store.serializerFor( - relationType - ); - var serializer = new Serializer(); + var relationMeta = snapshot.record[dirty].meta(); + var relationType = relationMeta.type; + var Serializer = relationMeta.options.serializer || store.serializerFor( + relationType + ); + var serializer = new Serializer(); return { data: snapshot.record.get(dirty).map((record) => { - return serializer.serialize(new DS.Snapshot(record._internalModel)); - }) + return serializer.serialize(new DS.Snapshot(record._internalModel)); + }) }; }, - updateRecord(store, type, snapshot) { - var dirtyRelationships = snapshot.record.get('dirtyRelationships'); - if (dirtyRelationships.length) { - var dirty = dirtyRelationships[0]; - var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord', dirty); - return this.ajax(url, 'PATCH', { + updateRecord(store, type, snapshot, _, query) { + var dirtyRelationships = snapshot.record.get('dirtyRelationships'); + if (dirtyRelationships.length) { + var dirty = dirtyRelationships.pop(); + var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord', query, dirty); + return this.ajax(url, 'PATCH', { data: this.relationshipPayload(snapshot, dirty, store) }); - } else { + } else { return this._super(...arguments); - } + } } }); diff --git a/addon/mixins/osf-model.js b/addon/mixins/osf-model.js index 83d18850a..a028e3242 100644 --- a/addon/mixins/osf-model.js +++ b/addon/mixins/osf-model.js @@ -11,26 +11,30 @@ export default Ember.Mixin.create({ relationshipLinks: DS.attr('links'), dirtyRelationships: Ember.computed('_dirtyRelationships', function() { - var dirtyRelationships = this.get('_dirtyRelationships'); + var dirtyRelationships = this.get('_dirtyRelationships'); return Object.keys(dirtyRelationships).map((rel) => { - if (rel === 'files') { - return null; - } - if (dirtyRelationships[rel]) { - return rel; - } - return null; + if (rel === 'files') { + return null; + } + if (dirtyRelationships[rel]) { + return rel; + } + return null; }).filter(Boolean); }), _dirtyRelationships: {}, onLoad: Ember.on('ready', function() { - this.eachRelationship((rel) => { + this.eachRelationship((rel, meta) => { let update = function() { let key = `_dirtyRelationships.${rel}`; this.set(key, !Ember.isEmpty(this.get(key))); }.bind(this); this.get(rel).then(() => { + var watch = rel; + if (meta.kind === 'hasMany') { + watch = `${rel}.[]`; + } this.addObserver(rel, update); }); }); From 473e3da4458485a1e1a60025221cf86798ebea15 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 16:53:39 -0400 Subject: [PATCH 245/959] Function docstring Ember convention defaults to YUIDoc, same as COSDev. https://github.com/emberjs/ember.js/blob/master/STYLEGUIDE.md#comments [ci skip] --- addon/mixins/paginated-route.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addon/mixins/paginated-route.js b/addon/mixins/paginated-route.js index 57ed66173..cbe10710e 100644 --- a/addon/mixins/paginated-route.js +++ b/addon/mixins/paginated-route.js @@ -16,7 +16,13 @@ export default Ember.Mixin.create({ pageArg: 'page', pageSizeArg: 'page[size]', - /* Convenience method. Given a model name (and optional user params), fetch a page of records. */ + /** + * @method queryForPage Fetch a route-specifed page of results from an external API + * @param modelName The name of the model to query in the store + * @param routeParams Parameters gictionary available to the model hook; must be passed in manually + * @param userParams Additional user-specified query parameters + * @returns {Promise} + */ queryForPage(modelName, routeParams, userParams) { let params = Object.assign({}, userParams || {}, routeParams); // If page_size is present, rename the url arg to to whatever URL param name the API server expects From 5f64cd77d781c7622feb767721a1503e03934765 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 17:28:32 -0400 Subject: [PATCH 246/959] Attach basic pagination data (total and per_page) to meta field. Track pagination on users page. [ci skip] --- addon/mixins/paginated-controller.js | 16 ++++++++++------ addon/serializers/osf-serializer.js | 10 +++++++++- tests/dummy/app/templates/users/list.hbs | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/addon/mixins/paginated-controller.js b/addon/mixins/paginated-controller.js index 819830aa8..6f416fd17 100644 --- a/addon/mixins/paginated-controller.js +++ b/addon/mixins/paginated-controller.js @@ -2,13 +2,17 @@ import Ember from 'ember'; export default Ember.Mixin.create({ queryParams: ['page', 'page_size'], - // TODO: Confirm that setting to null causes server to use its default values - page: 1, - page_size: null, + page: 1, // Current page + page_size: null, // Number of results per page. Param may be omitted. - // Placeholders, may use pagination metadata to track this instead - firstPage: null, - lastPage: null, + totalResults: Ember.computed('model', function() { + return this.get('model.meta.pagination.total'); + }), + totalPages: Ember.computed('model', 'totalResults', function() { + let results = this.get('totalResults'); + let pageSize = this.get('model.meta.pagination.per_page'); + return Math.ceil(results / pageSize); + }), actions: { previous() { diff --git a/addon/serializers/osf-serializer.js b/addon/serializers/osf-serializer.js index 1616a1e86..f6778d49c 100644 --- a/addon/serializers/osf-serializer.js +++ b/addon/serializers/osf-serializer.js @@ -53,6 +53,14 @@ export default DS.JSONAPISerializer.extend({ if (val !== undefined) { this._super(...arguments); } - } + }, + normalizeArrayResponse(store, primaryModelClass, payload, id, requestType){ // jshint ignore:line + // Ember data does not yet support pagination. For any request that returns more than one result, extract + // links.meta from the payload links section, and add to the model metadata manually. + let documentHash = this._super(...arguments); + documentHash.meta = documentHash.meta || {}; + documentHash.meta.pagination = Ember.get(payload || {}, 'links.meta'); + return documentHash; + } }); diff --git a/tests/dummy/app/templates/users/list.hbs b/tests/dummy/app/templates/users/list.hbs index 129aac0cb..3fbfbc18f 100644 --- a/tests/dummy/app/templates/users/list.hbs +++ b/tests/dummy/app/templates/users/list.hbs @@ -1,7 +1,7 @@

    Users

    - Current Page: {{page}} + Current Page: {{page}} out of {{totalPages}}

    From dbc89feef3cf309d1c9b6c3ac6877e1460f70473 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 19 May 2016 18:00:02 -0400 Subject: [PATCH 247/959] Add file-manager tests [skip-ci] --- tests/unit/services/file-manager-test.js | 557 ++++++++++++++++++++++- 1 file changed, 551 insertions(+), 6 deletions(-) diff --git a/tests/unit/services/file-manager-test.js b/tests/unit/services/file-manager-test.js index f01138a66..a8aabb7c2 100644 --- a/tests/unit/services/file-manager-test.js +++ b/tests/unit/services/file-manager-test.js @@ -1,12 +1,557 @@ +import Ember from 'ember'; import { moduleFor, test } from 'ember-qunit'; +function getFakeFile() { + return Ember.Object.create({ + id: 'blip', + links: { + download: '/this/is/a/download/url', + upload: '/this/is/an/upload/url', + new_folder: '/this/is/a/new_folder/url', + move: '/this/is/a/move/url', + delete: '/this/is/a/delete/url' + } + }); +} + +let ajaxOptionsHandler = null; +let ajaxTransport = null; + +function setupAjax(assert, expectedRequest, response) { + // Whenever $.ajax() is called, instead of actually sending anything just + // check the request matches what's expected, then + // pretend a server responded with the given response. + // Asserts once for each provided option and header, plus once for the + // URL and once more if query params are expected + + ajaxOptionsHandler = function(options) { + assertURL(assert, options.url, expectedRequest.url, + expectedRequest.query); + + for (let o in expectedRequest.options) { + // Check for a JSON payload + if (typeof expectedRequest.options[o] == 'object' && + typeof options[o] == 'string') { + let payload = JSON.parse(options[o]); + assert.deepEqual(payload, expectedRequest.options[o], + `request has expected JSON payload '${o}'`); + } else { + assert.equal(options[o], expectedRequest.options[o], + `request has expected option '${o}'`); + } + } + }; + + ajaxTransport = function(headers, callback) { + for (let h in expectedRequest.headers) { + assert.equal(headers[h], expectedRequest.headers[h], + `request has expected header '${h}'`); + } + callback(response.status, response.statusText, { text: response.data }); + }; +} + +// asserts once for the base URL and once more if queryParams are given +function assertURL(assert, actual, expected, queryParams) { + if (!queryParams) { + assert.equal(actual, expected, 'correct request URL'); + return; + } + let [actualBase, actualParams] = actual.split('?'); + assert.equal(actualBase, expected, 'correct base URL'); + + let expectedParams = []; + for(let key in queryParams) { + expectedParams.push(`${key}=${queryParams[key]}`); + } + assert.deepEqual(actualParams.split('&').sort(), expectedParams.sort(), + 'correct query params'); +} + +let fakeAccessToken = 'thisisafakeaccesstoken'; +let sessionStub = Ember.Service.extend({ + data: { + authenticated: { + attributes: { + accessToken: fakeAccessToken + } + } + } +}); + moduleFor('service:file-manager', 'Unit | Service | file manager', { - // Specify the other units that are required for this test. - // needs: ['service:foo'] + unit: true, + needs: ['model:file'], + beforeSetup() { + Ember.$.ajaxTransport('+*', function(options) { + if (ajaxOptionsHandler) { + ajaxOptionsHandler(options); + } + if (ajaxTransport) { + return { + send: ajaxTransport, + abort() {} + }; + } + }); + }, + beforeEach() { + this.register('service:session', sessionStub); + }, + afterEach() { + ajaxOptionsHandler = null; + ajaxTransport = null; + }, +}); + +test('getContents sends valid waterbutler request', function(assert) { + assert.expect(4); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.download, + options: { method: 'GET' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` } + }; + let response = { + status: 200, + statusText: 'ok', + data: 'file contents here' + }; + setupAjax(assert, request, response); + + service.getContents(file).then(function(data) { + assert.equal(data, response.data); + done(); + }).catch(function() { + done(); + }); +}); + +test('getContents passes along error', function(assert) { + assert.expect(4); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.download, + options: { method: 'GET' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` } + }; + let response = { + status: 404, + statusText: 'missing!' + }; + setupAjax(assert, request, response); + + service.getContents(file).then(function(data) { + done(); + }).catch(function(message) { + assert.equal(message, response.statusText, 'correct error message'); + done(); + }); +}); + +test('updateContents sends valid waterbutler request', function(assert) { + assert.expect(6); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.upload, + query: { kind: 'file' }, + options: { method: 'PUT', data: 'contents contents!' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 200, + statusText: 'ok' + }; + setupAjax(assert, request, response); + + service.updateContents(file, request.options.data).then(function(data) { + assert.equal(data, response.data); + done(); + }).catch(function() { + done(); + }); +}); + +test('updateContents passes along error', function(assert) { + assert.expect(6); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.upload, + query: { kind: 'file' }, + options: { method: 'PUT', data: 'contents contents' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 404, + statusText: 'missing!' + }; + setupAjax(assert, request, response); + + service.updateContents(file, request.options.data).then(function(data) { + done(); + }).catch(function(message) { + assert.equal(message, response.statusText); + done(); + }); +}); + +test('addSubfolder sends valid waterbutler request', function(assert) { + assert.expect(5); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.new_folder, + query: { name: 'fooname', kind: 'folder' }, + options: { method: 'PUT' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 200, + statusText: 'ok' + }; + setupAjax(assert, request, response); + + service.addSubfolder(file, request.query.name).then(function(data) { + assert.equal(data, response.data); + done(); + }).catch(function() { + done(); + }); +}); + +test('addSubfolder passes along error', function(assert) { + assert.expect(5); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.new_folder, + query: { name: 'fooname', kind: 'folder' }, + options: { method: 'PUT' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 404, + statusText: 'missing!' + }; + setupAjax(assert, request, response); + + service.addSubfolder(file, request.query.name).then(function(data) { + done(); + }).catch(function(message) { + assert.equal(message, response.statusText, 'correct error message'); + done(); + }); +}); + +test('uploadFile sends valid waterbutler request', function(assert) { + assert.expect(6); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.upload, + query: { name: 'fooname', kind: 'file' }, + options: { method: 'PUT', data: 'contents contents' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 200, + statusText: 'ok' + }; + setupAjax(assert, request, response); + + service.uploadFile(file, request.query.name, + request.options.data).then(function(data) { + assert.equal(data, response.data); + done(); + }).catch(function() { + done(); + }); +}); + +test('uploadFile passes along error', function(assert) { + assert.expect(6); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.upload, + query: { name: 'fooname', kind: 'file' }, + options: { method: 'PUT', data: 'contents contents' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 401, + statusText: 'bad' + }; + setupAjax(assert, request, response); + + service.uploadFile(file, request.query.name, + request.options.data).then(function() { + done(); + }).catch(function(error) { + assert.equal(error, response.statusText); + done(); + }); +}); + +test('move sends valid waterbutler request', function(assert) { + assert.expect(5); + let service = this.subject(); + let done = assert.async(); + let file = getFakeFile(); + let folder = getFakeFile(); + folder.set('path', '/path/path/this/is/a/path/'); + + let request = { + url: file.links.move, + options: { method: 'POST', data: { + action: 'move', + path: folder.get('path'), + conflict: 'replace' + } + }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 200, + statusText: 'ok', + data: { + data: { + attributes: {} + } + } + }; + setupAjax(assert, request, response); + + service.move(file, folder, {}).then(function(movedFile) { + assert.equal(movedFile.get('id'), file.get('id')); + done(); + }).catch(function() { + done(); + }); +}); + +test('move passes along error', function(assert) { + assert.expect(5); + let service = this.subject(); + let done = assert.async(); + let file = getFakeFile(); + let folder = getFakeFile(); + folder.set('path', '/path/path/this/is/a/path/'); + + let request = { + url: file.links.move, + options: { method: 'POST', data: { + action: 'move', + path: folder.get('path'), + conflict: 'replace' + } + }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 402, + statusText: 'oh no' + }; + setupAjax(assert, request, response); + + service.move(file, folder, {}).then(function() { + done(); + }).catch(function(error) { + assert.equal(error, response.statusText); + done(); + }); +}); + +test('copy sends valid waterbutler request', function(assert) { + assert.expect(5); + let service = this.subject(); + let done = assert.async(); + let file = getFakeFile(); + let folder = getFakeFile(); + folder.set('path', '/path/path/this/is/a/path/'); + + let request = { + url: file.links.move, + options: { method: 'POST', data: { + action: 'copy', + path: folder.get('path'), + conflict: 'replace' + } + }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 200, + statusText: 'ok', + data: { + data: { + attributes: {} + } + } + }; + setupAjax(assert, request, response); + + service.copy(file, folder, {}).then(function() { + assert.ok(true); + done(); + }).catch(function() { + done(); + }); }); -// Replace this with your real tests. -test('it exists', function(assert) { - let service = this.subject(); - assert.ok(service); +test('copy passes along error', function(assert) { + assert.expect(5); + let service = this.subject(); + let done = assert.async(); + let file = getFakeFile(); + let folder = getFakeFile(); + folder.set('path', '/path/path/this/is/a/path/'); + + let request = { + url: file.links.move, + options: { method: 'POST', data: { + action: 'copy', + path: folder.get('path'), + conflict: 'replace' + } + }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 402, + statusText: 'oh no' + }; + setupAjax(assert, request, response); + + service.copy(file, folder, {}).then(function() { + done(); + }).catch(function(error) { + assert.equal(error, response.statusText); + done(); + }); +}); + +test('rename sends valid waterbutler request', function(assert) { + assert.expect(5); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.move, + options: { method: 'POST', data: { action: 'rename', rename: 'flooby' } }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 200, + statusText: 'ok', + data: { + data: { + attributes: {} + } + } + }; + setupAjax(assert, request, response); + + service.rename(file, request.options.data.rename).then(function(renamed) { + assert.equal(renamed.get('id'), file.get('id')); + done(); + }).catch(function() { + done(); + }); +}); + +test('rename passes along error', function(assert) { + assert.expect(5); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.move, + options: { method: 'POST', data: { action: 'rename', rename: 'flooby' } }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 401, + statusText: 'bad' + }; + setupAjax(assert, request, response); + + service.rename(file, request.options.data.rename).then(function() { + done(); + }).catch(function(error) { + assert.equal(error, response.statusText); + done(); + }); +}); + +test('deleteFile sends valid waterbutler request', function(assert) { + assert.expect(4); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.delete, + options: { method: 'DELETE' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 200, + statusText: 'ok' + }; + setupAjax(assert, request, response); + + service.deleteFile(file).then(function() { + assert.ok(true); + done(); + }).catch(function() { + done(); + }); +}); + +test('deleteFile passes along error', function(assert) { + assert.expect(4); + let service = this.subject(); + let file = getFakeFile(); + let done = assert.async(); + + let request = { + url: file.links.delete, + options: { method: 'DELETE' }, + headers: { Authorization: `Bearer ${fakeAccessToken}` }, + }; + let response = { + status: 401, + statusText: 'bad' + }; + setupAjax(assert, request, response); + + service.deleteFile(file).then(function() { + done(); + }).catch(function(error) { + assert.equal(error, response.statusText); + done(); + }); }); From f58e48ca3eba177d63353389fb393b9b39c3efec Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Thu, 19 May 2016 18:00:44 -0400 Subject: [PATCH 248/959] Give up on reloading OSF file info for new files At least for now. [skip ci] --- addon/services/file-manager.js | 84 +++++++++---------- .../app/components/file-actions/component.js | 5 +- tests/dummy/app/routes/nodes/detail/files.js | 2 +- 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index 1cb5c882e..f5d3e3fff 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -4,23 +4,33 @@ export default Ember.Service.extend({ session: Ember.inject.service(), store: Ember.inject.service(), - // TODO: After each waterbutler action, either update the Ember - // store based on the returned WB entity (when possible), or force a - // refresh of file info through the OSF. Or maybe both? + // TODO: After performing a Waterbutler action, it takes a little while + // (maybe a minute, depending on caching options) for the OSF API to catch + // up and start serving the updated metadata. + // + // For actions on existing entities, this is fine, and file-manager + // uses info from WB to update the Ember store so everything looks right + // to the user, right away. + // + // For actions that create entities (addSubfolder, uploadFile, copy), + // this is a problem, because we need the OSF info (guid, WB links) + // before letting the user do anything to their new file. At the moment, + // after you create a file, you should go get a cup of coffee, come back, + // and hard reload. // File actions getContents(file) { - var url = file.get('links').download; + let url = file.get('links').download; return this._waterbutlerRequest('GET', url); }, updateContents(file, contents) { - var url = file.get('links').upload; - var params = { kind: 'file' }; - return this._waterbutlerRequest('PUT', url, params); + let url = file.get('links').upload; + let params = { kind: 'file' }; + return this._waterbutlerRequest('PUT', url, params, contents); }, - checkout(file, user) { + checkout(/*file, user*/) { // TODO? Having checkout here makes more sense to me than making it // the only writable attribute on the file model. }, @@ -38,45 +48,32 @@ export default Ember.Service.extend({ if (queryStart > -1) { url = url.slice(0, queryStart); } - - let store = this.get('store'); - - let p = this._waterbutlerRequest('PUT', url, params); - return p.then((data) => { - // TODO: figure out how to force a reload that actually works - this.get('store').findRecord('file', folder.get('id'), {reload: true}); - }); - + return this._waterbutlerRequest('PUT', url, params); }, uploadFile(folder, name, contents) { - var url = folder.get('links').upload; - var params = { + let url = folder.get('links').upload; + let params = { name, kind: 'file' }; - var p = this._waterbutlerRequest('PUT', url, params, contents); - return p.then((data) => { - // TODO: figure out how to force a reload that actually works - this.get('store').findRecord('file', folder.get('id'), {reload: true}); - }); + return this._waterbutlerRequest('PUT', url, params, contents); }, // File and folder actions rename(file, newName) { - var url = file.get('links').move; - var data = JSON.stringify({ action: 'rename', rename: newName }); - var p = this._waterbutlerRequest('POST', url, null, data); + let url = file.get('links').move; + let data = JSON.stringify({ action: 'rename', rename: newName }); + let p = this._waterbutlerRequest('POST', url, null, data); return p.then((data) => { - data.data.id = file.get('id'); - return this._addFileToStore(data); + return this._pushToStore(data, file.get('id')); }); }, move(file, targetFolder, { newName=null, replace=true, node=null, provider=null, copy=false }) { - var url = file.get('links').move; - var data = { + let url = file.get('links').move; + let data = { action: copy ? 'copy' : 'move', path: targetFolder.get('path'), conflict: replace ? 'replace' : 'keep' @@ -95,13 +92,13 @@ export default Ember.Service.extend({ data.provider = provider; } - var p = this._waterbutlerRequest('POST', url, null, JSON.stringify(data)); + let p = this._waterbutlerRequest('POST', url, null, JSON.stringify(data)); return p.then((data) => { - if (!copy) { - data.data.id = file.get('id'); + if (copy) { + // TODO get new file's info from OSF + } else { + return this._pushToStore(data, file.get('id'), targetFolder); } - // TODO force reload on copy - return this._addFileToStore(data, targetFolder); }); }, @@ -112,8 +109,8 @@ export default Ember.Service.extend({ }, deleteFile(file) { - var url = file.get('links').delete; - var p = this._waterbutlerRequest('DELETE', url); + let url = file.get('links').delete; + let p = this._waterbutlerRequest('DELETE', url); return p.then(() => { let parentFolder = file.get('parentFolder'); if (parentFolder) { @@ -127,8 +124,8 @@ export default Ember.Service.extend({ let queryString = Ember.$.param(queryParams); url = `${url}?${queryString}`; } - var sessionData = this.get('session').get('data').authenticated; - var accessToken = sessionData.attributes.accessToken; + let sessionData = this.get('session').get('data').authenticated; + let accessToken = sessionData.attributes.accessToken; return new Ember.RSVP.Promise((resolve, reject) => { Ember.$.ajax(url, { @@ -139,13 +136,16 @@ export default Ember.Service.extend({ Authorization: `Bearer ${accessToken}` }, success: (data) => resolve(data), - fail: (_, __, error) => reject(error) + error: (_, __, error) => { + reject(error); + } }); }); }, - _addFileToStore(data, parentFolder) { + _pushToStore(data, id, parentFolder) { // Hack the Waterbutler entity to look like the file Ember expects + data.data.id = id; data.data.type = 'file'; let attr = data.data.attributes; attr.materializedPath = attr.materialized; diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index c63b9b473..07021b726 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -48,7 +48,6 @@ export default Ember.Component.extend({ let file = this.get('file'); if (newName) { let p = this.get('fileManager').rename(file, newName); - let onChange = this.get('onChange'); p.then(() => { file.set('name', newName); this.get('onChange')(); @@ -71,9 +70,9 @@ export default Ember.Component.extend({ if (!folder) { folder = store.peekRecord('file-provider', folderId); if (!folder) { - debugger; + // TODO errors + return; } - // TODO errors } let options = { node: this.get('moveNode'), diff --git a/tests/dummy/app/routes/nodes/detail/files.js b/tests/dummy/app/routes/nodes/detail/files.js index 98fe1bbf2..489a920c7 100644 --- a/tests/dummy/app/routes/nodes/detail/files.js +++ b/tests/dummy/app/routes/nodes/detail/files.js @@ -2,7 +2,7 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; export default Ember.Route.extend(AuthenticatedRouteMixin, { - model(params) { + model() { let node = this.modelFor('nodes.detail'); return node.get('files'); }, From 670cb1e9fb44b2c0c3815e449f5ba478da6ce995 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 18:02:33 -0400 Subject: [PATCH 249/959] Make pagination params configurable (jsonapi spec calls for page[number], so might as well get out in front of that) [ci skip] --- addon/mixins/paginated-controller.js | 3 --- addon/mixins/paginated-route.js | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/addon/mixins/paginated-controller.js b/addon/mixins/paginated-controller.js index 6f416fd17..beb1c970a 100644 --- a/addon/mixins/paginated-controller.js +++ b/addon/mixins/paginated-controller.js @@ -18,15 +18,12 @@ export default Ember.Mixin.create({ previous() { // TODO: Add bounds checking somewhere this.decrementProperty('page', 1); - console.log('decrement to previous'); }, next() { this.incrementProperty('page', 1); - console.log('increment to next'); }, goToPage(pageNumber) { this.set('page', pageNumber); - console.log('Went to page: ', this.get('page')); } } }); diff --git a/addon/mixins/paginated-route.js b/addon/mixins/paginated-route.js index cbe10710e..0b4ff540d 100644 --- a/addon/mixins/paginated-route.js +++ b/addon/mixins/paginated-route.js @@ -11,10 +11,12 @@ export default Ember.Mixin.create({ } }, - // Allow support for different APIs, by making the API pagination query param names configurable. Most users will not need to change this. - // TODO: Use these - pageArg: 'page', - pageSizeArg: 'page[size]', + // Configure how pagination query params in the frontend map to the query params expected by the API backend + // (helps support different APIs). Most users will not need to change this. + apiArgs: { + page: 'page', + page_size: 'page[size]' + }, /** * @method queryForPage Fetch a route-specifed page of results from an external API @@ -25,12 +27,18 @@ export default Ember.Mixin.create({ */ queryForPage(modelName, routeParams, userParams) { let params = Object.assign({}, userParams || {}, routeParams); - // If page_size is present, rename the url arg to to whatever URL param name the API server expects - if (params.page_size) { - // TODO: support making api pagination param names configurable - params['page[size]'] = params.page_size; + + // Rename parameters to match what the API expects, and remove the old param name if necessary + let apiArgs = this.get('apiArgs'); + for (let frontEndParamName of Object.keys(apiArgs)) { + let backEndParamName = apiArgs[frontEndParamName]; + if (params[frontEndParamName]) { + params[backEndParamName] = params[frontEndParamName]; + } + if (frontEndParamName !== backEndParamName) { + delete params[frontEndParamName]; + } } - delete params.page_size; return this.store.query(modelName, params); } }); From 2ca57d15a3ca3d21c6a85bba33c58540c6797f59 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 18:50:19 -0400 Subject: [PATCH 250/959] Make editorconfig consistent with 2-space preference of template linter [ci skip] --- .editorconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3ef6636ee..cec8c9204 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,7 +20,7 @@ indent_size = 4 [*.hbs] insert_final_newline = false indent_style = space -indent_size = 4 +indent_size = 2 [*.css] indent_style = space @@ -28,7 +28,7 @@ indent_size = 4 [*.html] indent_style = space -indent_size = 4 +indent_size = 2 [*.{diff,md}] trim_trailing_whitespace = false From 45393690b7efe7e4956bfe8cddca8ba5bc06b699 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 18:55:08 -0400 Subject: [PATCH 251/959] Add simple pagination component as proof of concept, and put on users page Also get tests passing --- .../pagination-control/component.js | 23 +++++++++++++++++++ .../pagination-control/template.hbs | 8 +++++++ .../pagination-control/component.js | 1 + tests/dummy/app/templates/users/list.hbs | 11 +++++---- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 addon/components/pagination-control/component.js create mode 100644 addon/components/pagination-control/template.hbs create mode 100644 app/components/pagination-control/component.js diff --git a/addon/components/pagination-control/component.js b/addon/components/pagination-control/component.js new file mode 100644 index 000000000..ec049f863 --- /dev/null +++ b/addon/components/pagination-control/component.js @@ -0,0 +1,23 @@ +import Ember from 'ember'; +import layout from './template'; + +export default Ember.Component.extend({ + layout, + currentPage: null, + pageCount: null, + + // TODO: This actions hash feels a bit kludgy + actions: { + next() { + return this.sendAction('next', ...arguments); + }, + + previous() { + return this.sendAction('previous', ...arguments); + }, + + goToPage(pageNumber) { + return this.sendAction('goToPage', pageNumber); + } + } +}); diff --git a/addon/components/pagination-control/template.hbs b/addon/components/pagination-control/template.hbs new file mode 100644 index 000000000..e43812cd2 --- /dev/null +++ b/addon/components/pagination-control/template.hbs @@ -0,0 +1,8 @@ +
    + + +
    + +
    + Page of {{pageCount}} +
    diff --git a/app/components/pagination-control/component.js b/app/components/pagination-control/component.js new file mode 100644 index 000000000..070fe0548 --- /dev/null +++ b/app/components/pagination-control/component.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/pagination-control/component'; \ No newline at end of file diff --git a/tests/dummy/app/templates/users/list.hbs b/tests/dummy/app/templates/users/list.hbs index 3fbfbc18f..2dab41947 100644 --- a/tests/dummy/app/templates/users/list.hbs +++ b/tests/dummy/app/templates/users/list.hbs @@ -1,12 +1,15 @@

    Users

    - Current Page: {{page}} out of {{totalPages}} + {{pagination-control + currentPage=page + pageCount=totalPages + next=(action 'next') + previous=(action 'previous') + goToPage=(action 'goToPage') + }}

    - - -
    {{#each model as |user|}}
    From b38bf96887b7f1c474e72efd2a18f34cfbde0db6 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 18:59:21 -0400 Subject: [PATCH 252/959] One linter is an angry god. What we have here is a pantheon. --- addon/serializers/osf-serializer.js | 2 +- app/components/pagination-control/component.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/serializers/osf-serializer.js b/addon/serializers/osf-serializer.js index f6778d49c..d1619b375 100644 --- a/addon/serializers/osf-serializer.js +++ b/addon/serializers/osf-serializer.js @@ -55,7 +55,7 @@ export default DS.JSONAPISerializer.extend({ } }, - normalizeArrayResponse(store, primaryModelClass, payload, id, requestType){ // jshint ignore:line + normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) { // jshint ignore:line // Ember data does not yet support pagination. For any request that returns more than one result, extract // links.meta from the payload links section, and add to the model metadata manually. let documentHash = this._super(...arguments); diff --git a/app/components/pagination-control/component.js b/app/components/pagination-control/component.js index 070fe0548..d61667e12 100644 --- a/app/components/pagination-control/component.js +++ b/app/components/pagination-control/component.js @@ -1 +1 @@ -export { default } from 'ember-osf/components/pagination-control/component'; \ No newline at end of file +export { default } from 'ember-osf/components/pagination-control/component'; From a8482e6adc31d113845df148178e77c9760a60f4 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Thu, 19 May 2016 19:09:00 -0400 Subject: [PATCH 253/959] Don't allow fwd/reverse pagination to invalid page Future improvement: bounds checking for goto box --- addon/components/pagination-control/component.js | 6 ++++++ addon/components/pagination-control/template.hbs | 4 ++-- addon/mixins/paginated-controller.js | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addon/components/pagination-control/component.js b/addon/components/pagination-control/component.js index ec049f863..9b6bfa62c 100644 --- a/addon/components/pagination-control/component.js +++ b/addon/components/pagination-control/component.js @@ -6,6 +6,12 @@ export default Ember.Component.extend({ currentPage: null, pageCount: null, + // Bounds checking for control buttons + disablePageReverse: Ember.computed.lte('currentPage', 1), + disablePageForward: Ember.computed('currentPage', 'pageCount', function() { + return this.get('currentPage') >= this.get('pageCount'); + }), + // TODO: This actions hash feels a bit kludgy actions: { next() { diff --git a/addon/components/pagination-control/template.hbs b/addon/components/pagination-control/template.hbs index e43812cd2..a642ac9cc 100644 --- a/addon/components/pagination-control/template.hbs +++ b/addon/components/pagination-control/template.hbs @@ -1,6 +1,6 @@
    - - + +
    diff --git a/addon/mixins/paginated-controller.js b/addon/mixins/paginated-controller.js index beb1c970a..1320ef419 100644 --- a/addon/mixins/paginated-controller.js +++ b/addon/mixins/paginated-controller.js @@ -16,7 +16,6 @@ export default Ember.Mixin.create({ actions: { previous() { - // TODO: Add bounds checking somewhere this.decrementProperty('page', 1); }, next() { From 80a36ffc6850210f3c5c066cc7d24b9ef4c98cf0 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 09:15:45 -0400 Subject: [PATCH 254/959] Fix jshint errors [skip ci] --- tests/dummy/app/components/file-tree/component.js | 2 +- tests/unit/services/file-manager-test.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/dummy/app/components/file-tree/component.js b/tests/dummy/app/components/file-tree/component.js index 5df74b27d..44bf16cc0 100644 --- a/tests/dummy/app/components/file-tree/component.js +++ b/tests/dummy/app/components/file-tree/component.js @@ -2,5 +2,5 @@ import Ember from 'ember'; import layout from './template'; export default Ember.Component.extend({ - layout, + layout }); diff --git a/tests/unit/services/file-manager-test.js b/tests/unit/services/file-manager-test.js index a8aabb7c2..cbfe43d46 100644 --- a/tests/unit/services/file-manager-test.js +++ b/tests/unit/services/file-manager-test.js @@ -30,8 +30,8 @@ function setupAjax(assert, expectedRequest, response) { for (let o in expectedRequest.options) { // Check for a JSON payload - if (typeof expectedRequest.options[o] == 'object' && - typeof options[o] == 'string') { + if (typeof expectedRequest.options[o] === 'object' && + typeof options[o] === 'string') { let payload = JSON.parse(options[o]); assert.deepEqual(payload, expectedRequest.options[o], `request has expected JSON payload '${o}'`); @@ -147,7 +147,7 @@ test('getContents passes along error', function(assert) { }; setupAjax(assert, request, response); - service.getContents(file).then(function(data) { + service.getContents(file).then(function() { done(); }).catch(function(message) { assert.equal(message, response.statusText, 'correct error message'); @@ -199,7 +199,7 @@ test('updateContents passes along error', function(assert) { }; setupAjax(assert, request, response); - service.updateContents(file, request.options.data).then(function(data) { + service.updateContents(file, request.options.data).then(function() { done(); }).catch(function(message) { assert.equal(message, response.statusText); @@ -251,7 +251,7 @@ test('addSubfolder passes along error', function(assert) { }; setupAjax(assert, request, response); - service.addSubfolder(file, request.query.name).then(function(data) { + service.addSubfolder(file, request.query.name).then(function() { done(); }).catch(function(message) { assert.equal(message, response.statusText, 'correct error message'); From 2b72f42077c43d21917fe3a3169ed6bf734ccb22 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 09:27:35 -0400 Subject: [PATCH 255/959] Remove unused file [skip ci] --- tests/dummy/app/components/file-tree/style.scss | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 tests/dummy/app/components/file-tree/style.scss diff --git a/tests/dummy/app/components/file-tree/style.scss b/tests/dummy/app/components/file-tree/style.scss deleted file mode 100644 index 7ee6ca5c9..000000000 --- a/tests/dummy/app/components/file-tree/style.scss +++ /dev/null @@ -1,7 +0,0 @@ -.files-tree { - padding-left: 1em; -} - -.files-tree .folder-list { - border-left: 1px solid #ccc; -} From aa0f42b7baddf391a9c9f03ee9b9159b15e2086e Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 20 May 2016 09:51:48 -0400 Subject: [PATCH 256/959] model -> version; slight tweak to file-version semantics --- addon/components/file-version/template.hbs | 6 +++--- tests/dummy/app/templates/file.hbs | 2 +- tests/integration/components/file-version/component-test.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/addon/components/file-version/template.hbs b/addon/components/file-version/template.hbs index 28127f04b..ee7910d40 100644 --- a/addon/components/file-version/template.hbs +++ b/addon/components/file-version/template.hbs @@ -1,6 +1,6 @@
  • -
    {{model.id}}
    -
    {{model.size}}
    -
    {{model.contentType}}
    +
    {{version.id}}
    +
    {{version.size}}
    +
    {{version.contentType}}
  • {{yield}} diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs index 1ef204770..b831b8a1e 100644 --- a/tests/dummy/app/templates/file.hbs +++ b/tests/dummy/app/templates/file.hbs @@ -15,7 +15,7 @@

    Versions

      {{#each model.versions as |version|}} - {{file-version model=version}} + {{file-version version=version}} {{else}} (none) {{/each}} diff --git a/tests/integration/components/file-version/component-test.js b/tests/integration/components/file-version/component-test.js index 04b2f9499..17dfcfe13 100644 --- a/tests/integration/components/file-version/component-test.js +++ b/tests/integration/components/file-version/component-test.js @@ -9,7 +9,7 @@ test('it renders', function(assert) { // Set any properties with this.set('myProperty', 'value'); // Handle any actions with this.on('myAction', function(val) { ... }); this.set('version', {'id': '1', 'size': 125, 'contentType': 'text'}); - this.render(hbs`{{file-version model=version}}`); + this.render(hbs`{{file-version version=version}}`); assert.equal(this.$().text().trim(), 'ID: 1\n Size: 125\n Content type: text'); From 48c6e7610c363329ea6733e03733d9e0a4de554b Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 20 May 2016 10:04:02 -0400 Subject: [PATCH 257/959] Don't style-check package.json Seems like this is a losing battle; npm has indent of 2 spaces hardcoded everywhere in its source :(. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 6fe6622ad..fe9a469f8 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "jscsConfig": { "preset": "airbnb", "excludeFiles": [ + "package.json", "bower_components", "dist", "tmp", From 559d68abcccbfcab40d5c43446c7e8e17a4236d1 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 20 May 2016 11:12:45 -0400 Subject: [PATCH 258/959] Add TODOs for code cleanup --- addon/adapters/contributor.js | 2 ++ tests/dummy/app/routes/nodes/detail.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/addon/adapters/contributor.js b/addon/adapters/contributor.js index 59f67af4e..88b7ada2a 100644 --- a/addon/adapters/contributor.js +++ b/addon/adapters/contributor.js @@ -2,6 +2,8 @@ import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ buildURL(_, __, snap) { + // TOOD: delete me when https://github.com/CenterForOpenScience/ember-osf/pull/34 is merged + // Modifies URL from /contributors to nodes//contributors/ to match APIv2 route for creating contributors. var base = this._super(...arguments); var ar = base.split('/'); diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index aa37273df..d79de8dff 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -1,5 +1,7 @@ import Ember from 'ember'; +// TODO: refactor permissions strings when https://github.com/CenterForOpenScience/ember-osf/pull/23/files#diff-7fd0bf247bef3c257e0fcfd7e544a338R5 is merged + export default Ember.Route.extend({ model(params) { From 254e5ca1659465a4d5e5bb3f2d064089078d05f2 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 20 May 2016 11:20:18 -0400 Subject: [PATCH 259/959] Remove ember-radio-button from package.son. --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 946544cbb..a41cc68ff 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "ember-export-application-global": "^1.0.4", "ember-i18n": "4.2.1", "ember-load-initializers": "0.5.1", - "ember-radio-button": "1.0.7", "ember-resolver": "2.0.3", "ember-sinon": "0.5.0", "ember-sinon-qunit": "1.3.1", From 353c5398d562f02d3a075e11007f0777ef956ec1 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 11:21:03 -0400 Subject: [PATCH 260/959] Change handlebars template indentation to 4 spaces Because 2 just wasn't enough. --- .template-lintrc.js | 6 +- .../app/components/files-tree/template.hbs | 20 ++--- .../app/components/log-detail/template.hbs | 44 +++++----- tests/dummy/app/templates/application.hbs | 12 +-- .../app/templates/collections/detail.hbs | 6 +- .../dummy/app/templates/collections/index.hbs | 20 ++--- tests/dummy/app/templates/file.hbs | 70 +++++++-------- .../app/templates/institutions/detail.hbs | 36 ++++---- .../app/templates/institutions/index.hbs | 26 +++--- tests/dummy/app/templates/nodes/detail.hbs | 84 +++++++++--------- tests/dummy/app/templates/nodes/index.hbs | 36 ++++---- tests/dummy/app/templates/profile.hbs | 26 +++--- .../app/templates/registrations/detail.hbs | 26 +++--- .../app/templates/registrations/index.hbs | 24 +++--- tests/dummy/app/templates/users/detail.hbs | 86 +++++++++---------- tests/dummy/app/templates/users/index.hbs | 22 ++--- 16 files changed, 274 insertions(+), 270 deletions(-) diff --git a/.template-lintrc.js b/.template-lintrc.js index 483261e8d..449e3dfc2 100644 --- a/.template-lintrc.js +++ b/.template-lintrc.js @@ -2,5 +2,9 @@ 'use strict'; module.exports = { - extends: 'recommended' + extends: 'recommended', + + rules: { + 'block-indentation': 4 + } }; diff --git a/tests/dummy/app/components/files-tree/template.hbs b/tests/dummy/app/components/files-tree/template.hbs index e6fe41e0f..4589ecb3b 100644 --- a/tests/dummy/app/components/files-tree/template.hbs +++ b/tests/dummy/app/components/files-tree/template.hbs @@ -1,12 +1,12 @@

      - - {{#if model.isFolder}} -

      - {{#each model.files as |file|}} - {{files-tree model=file}} - {{/each}} -

      - {{else}} - ({{link-to 'details' 'file' model}}) - {{/if}} + + {{#if model.isFolder}} +

      + {{#each model.files as |file|}} + {{files-tree model=file}} + {{/each}} +

      + {{else}} + ({{link-to 'details' 'file' model}}) + {{/if}}

      diff --git a/tests/dummy/app/components/log-detail/template.hbs b/tests/dummy/app/components/log-detail/template.hbs index 0d7f7ecc0..d2d6ac128 100644 --- a/tests/dummy/app/components/log-detail/template.hbs +++ b/tests/dummy/app/components/log-detail/template.hbs @@ -1,28 +1,28 @@

      Recent Activity

      - - - - - - - - - {{#each node-logs as |node-log|}} - - - - - - + + + + + + - {{/each}} + {{#each node-logs as |node-log|}} + + + + + + + + + {{/each}}
      Action Original Node User Current Node Date Additional Params Included
      {{node-log.action}} {{node-log.originalNode.title}}: {{node-log.originalNode.id}} {{node-log.user.givenName}} {{node-log.node.title}}: {{node-log.node.id}} {{moment-format node-log.date}} - {{#each-in node-log.params as |key value|}} - {{key}}, - {{/each-in}} - {{if node-log.linkedNode "linked_node"}} - {{if node-log.templateNode "template_node"}} - Action Original Node User Current Node Date Additional Params Included
      {{node-log.action}} {{node-log.originalNode.title}}: {{node-log.originalNode.id}} {{node-log.user.givenName}} {{node-log.node.title}}: {{node-log.node.id}} {{moment-format node-log.date}} + {{#each-in node-log.params as |key value|}} + {{key}}, + {{/each-in}} + {{if node-log.linkedNode "linked_node"}} + {{if node-log.templateNode "template_node"}} +
      diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index 5d6d4df6d..42e887b63 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1,9 +1,9 @@
      - {{link-to 'Home' 'index' class="btn btn-default"}} -

      Welcome to OSF Ember Example App

      -
      -
      - {{outlet}} + {{link-to 'Home' 'index' class="btn btn-default"}} +

      Welcome to OSF Ember Example App

      +
      +
      + {{outlet}} +
      -
      diff --git a/tests/dummy/app/templates/collections/detail.hbs b/tests/dummy/app/templates/collections/detail.hbs index be2b85311..eb98fb3c3 100644 --- a/tests/dummy/app/templates/collections/detail.hbs +++ b/tests/dummy/app/templates/collections/detail.hbs @@ -1,6 +1,6 @@ {{link-to 'Back to list' 'collections' class="btn btn-default"}}
      -

      {{model.title}}

      -

      {{moment-format model.dateCreated}}

      -

      {{moment-format model.dateModified}}

      +

      {{model.title}}

      +

      {{moment-format model.dateCreated}}

      +

      {{moment-format model.dateModified}}

      diff --git a/tests/dummy/app/templates/collections/index.hbs b/tests/dummy/app/templates/collections/index.hbs index 1281ec3a0..3520452cd 100644 --- a/tests/dummy/app/templates/collections/index.hbs +++ b/tests/dummy/app/templates/collections/index.hbs @@ -1,17 +1,17 @@

      Collections

      -
      Create Collection
      - {{input value=title placeholder="Collection's title" required=true}} - +
      Create Collection
      + {{input value=title placeholder="Collection's title" required=true}} +

      -
      Collections list
      - {{#each model as |collection|}} -

      Title: {{collection.title}}

      -

      Date created: {{moment-format collection.dateCreated}}

      -

      Date modified: {{moment-format collection.dateModified}}

      - {{link-to "Detail" "collections.detail" collection.id class="btn btn-primary"}} - {{/each}} +
      Collections list
      + {{#each model as |collection|}} +

      Title: {{collection.title}}

      +

      Date created: {{moment-format collection.dateCreated}}

      +

      Date modified: {{moment-format collection.dateModified}}

      + {{link-to "Detail" "collections.detail" collection.id class="btn btn-primary"}} + {{/each}}
      diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs index ed7cafa03..0ebad5595 100644 --- a/tests/dummy/app/templates/file.hbs +++ b/tests/dummy/app/templates/file.hbs @@ -1,38 +1,38 @@
      -

      File detail

      -

      {{model.name}}

      -

      {{model.kind}}

      -

      {{model.path}}

      -

      {{model.size}}

      -

      {{model.provider}}

      -

      {{model.materializedPath}}

      -

      {{model.lastTouched}}

      -

      {{model.dateModified}}

      -

      {{model.dateCreated}}

      -

      {{model.checkout}}

      +

      File detail

      +

      {{model.name}}

      +

      {{model.kind}}

      +

      {{model.path}}

      +

      {{model.size}}

      +

      {{model.provider}}

      +

      {{model.materializedPath}}

      +

      {{model.lastTouched}}

      +

      {{model.dateModified}}

      +

      {{model.dateCreated}}

      +

      {{model.checkout}}

      -
      -

      Versions

      -
        - {{#each model.versions as |version|}} -
      • -
        {{version.id}}
        -
        {{version.size}}
        -
        {{version.contentType}}
        -
      • - {{else}} - (none) - {{/each}} -
      -
      -

      Comments

      -
        - {{#each model.comments as |comment|}} -
      • -
        {{comment.content}}
        -
      • - {{else}} - (none) - {{/each}} -
      +
      +

      Versions

      +
        + {{#each model.versions as |version|}} +
      • +
        {{version.id}}
        +
        {{version.size}}
        +
        {{version.contentType}}
        +
      • + {{else}} + (none) + {{/each}} +
      +
      +

      Comments

      +
        + {{#each model.comments as |comment|}} +
      • +
        {{comment.content}}
        +
      • + {{else}} + (none) + {{/each}} +
      diff --git a/tests/dummy/app/templates/institutions/detail.hbs b/tests/dummy/app/templates/institutions/detail.hbs index 65d0c42fb..7927cb52d 100644 --- a/tests/dummy/app/templates/institutions/detail.hbs +++ b/tests/dummy/app/templates/institutions/detail.hbs @@ -1,23 +1,23 @@ {{link-to 'Back to list' 'institutions' class="btn btn-default"}}
      -

      {{model.name}}

      -

      {{model.description}}

      -

      {{model.logoPath}}

      -

      {{model.authUrl}}

      -
      -

      - +

      {{model.name}}

      +

      {{model.description}}

      +

      {{model.logoPath}}

      +

      {{model.authUrl}}

      +

      - - {{#each model.nodes as |node|}} - - {{node.title}} - - - {{node.description}} - - {{/each}} -
      + +

      + + {{#each model.nodes as |node|}} + + {{node.title}} + + + {{node.description}} + + {{/each}} +
      +

      -

      diff --git a/tests/dummy/app/templates/institutions/index.hbs b/tests/dummy/app/templates/institutions/index.hbs index c72d51f70..a0453baea 100644 --- a/tests/dummy/app/templates/institutions/index.hbs +++ b/tests/dummy/app/templates/institutions/index.hbs @@ -1,16 +1,16 @@

      All Institutions

      {{#each model as |inst|}} -
      -
      -

      {{inst.name}}

      -

      {{inst.description}}

      -

      {{inst.logoPath}}

      -

      {{inst.authUrl}}

      -

      - - View on OSF - - {{link-to 'Detail' 'institutions.detail' inst.id class="btn btn-primary"}} -

      -
      +
      +
      +

      {{inst.name}}

      +

      {{inst.description}}

      +

      {{inst.logoPath}}

      +

      {{inst.authUrl}}

      +

      + + View on OSF + + {{link-to 'Detail' 'institutions.detail' inst.id class="btn btn-primary"}} +

      +
      {{/each}} diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 8f1818dbe..3da10218f 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -1,46 +1,46 @@ {{link-to 'Back to list' 'nodes' class="btn btn-default"}}
      -

      Data

      -

      {{model.title}}

      -

      {{model.category}}

      -

      {{moment-format model.dateCreated}}

      -

      {{moment-format model.dateModified}}

      -

      - - View on OSF - -

      -
      -

      Edit this node

      - Title: {{input value=editedTitle}} - -

      Contributors

      - - - - - - {{#each model.contributors as |contrib|}} - - - - - {{/each}} -
      IDAuthor?
      {{contrib.id}}{{contrib.bibliographic}}
      - -

      +

      Data

      +

      {{model.title}}

      +

      {{model.category}}

      +

      {{moment-format model.dateCreated}}

      +

      {{moment-format model.dateModified}}

      +

      + + View on OSF + +

      +
      +

      Edit this node

      + Title: {{input value=editedTitle}} + +

      Contributors

      - {{#each model.affiliatedInstitutions as |inst|}} - - {{inst.name}} - - {{/each}} -
      -

      -

      Files

      - {{#each model.files as |provider|}} - {{files-tree model=provider}} - {{/each}} -
      - {{log-detail node-logs=model.logs}} + + ID + Author? + + {{#each model.contributors as |contrib|}} + + {{contrib.id}} + {{contrib.bibliographic}} + + {{/each}} + + +

      + + {{#each model.affiliatedInstitutions as |inst|}} + + {{inst.name}} + + {{/each}} +
      +

      +

      Files

      + {{#each model.files as |provider|}} + {{files-tree model=provider}} + {{/each}} +
      + {{log-detail node-logs=model.logs}}
      diff --git a/tests/dummy/app/templates/nodes/index.hbs b/tests/dummy/app/templates/nodes/index.hbs index a40388439..0e41c16d7 100644 --- a/tests/dummy/app/templates/nodes/index.hbs +++ b/tests/dummy/app/templates/nodes/index.hbs @@ -1,23 +1,23 @@

      My Nodes

      - - {{input type="text" value=title placeholder="Node's title" required=true}} - - {{input type="text" value=description placeholder="Node's description"}} -

      + + {{input type="text" value=title placeholder="Node's title" required=true}} + + {{input type="text" value=description placeholder="Node's description"}} +

      {{#each model as |node|}} -
      -
      -

      {{node.title}}

      -

      {{node.category}}

      -

      {{moment-format node.dateCreated}}

      -

      {{moment-format node.dateModified}}

      -

      - - View on OSF - - {{link-to 'Detail' 'nodes.detail' node.id class="btn btn-primary"}} -

      -
      +
      +
      +

      {{node.title}}

      +

      {{node.category}}

      +

      {{moment-format node.dateCreated}}

      +

      {{moment-format node.dateModified}}

      +

      + + View on OSF + + {{link-to 'Detail' 'nodes.detail' node.id class="btn btn-primary"}} +

      +
      {{/each}} diff --git a/tests/dummy/app/templates/profile.hbs b/tests/dummy/app/templates/profile.hbs index 5e18744eb..97e7aa359 100644 --- a/tests/dummy/app/templates/profile.hbs +++ b/tests/dummy/app/templates/profile.hbs @@ -1,18 +1,18 @@

      Profile Information

      -

      {{model.fullName}}

      -

      {{model.givenName}}

      -

      {{model.middleName}}

      -

      {{model.familyName}}

      +

      {{model.fullName}}

      +

      {{model.givenName}}

      +

      {{model.middleName}}

      +

      {{model.familyName}}

      -

      - - View on OSF - -

      -
      +

      + + View on OSF + +

      +
      -

      Edit your profile

      - Full Name: {{input value=editedFullName}} - +

      Edit your profile

      + Full Name: {{input value=editedFullName}} +
      diff --git a/tests/dummy/app/templates/registrations/detail.hbs b/tests/dummy/app/templates/registrations/detail.hbs index 711c7f091..1c0db0c68 100644 --- a/tests/dummy/app/templates/registrations/detail.hbs +++ b/tests/dummy/app/templates/registrations/detail.hbs @@ -1,16 +1,16 @@ {{link-to 'Back to list' 'registrations' class="btn btn-default"}}
      -

      {{model.title}}

      -

      {{model.category}}

      -

      {{moment-format model.dateRegistered}}

      -

      - - View on OSF - -

      -

      - {{link-to 'Node Registered' 'nodes.detail' model.registeredFrom.id class="btn btn-warning"}} -

      -
      - {{log-detail node-logs=model.logs}} +

      {{model.title}}

      +

      {{model.category}}

      +

      {{moment-format model.dateRegistered}}

      +

      + + View on OSF + +

      +

      + {{link-to 'Node Registered' 'nodes.detail' model.registeredFrom.id class="btn btn-warning"}} +

      +
      + {{log-detail node-logs=model.logs}}
      diff --git a/tests/dummy/app/templates/registrations/index.hbs b/tests/dummy/app/templates/registrations/index.hbs index 27796316b..6b47658be 100644 --- a/tests/dummy/app/templates/registrations/index.hbs +++ b/tests/dummy/app/templates/registrations/index.hbs @@ -1,15 +1,15 @@

      My Registrations

      {{#each model as |registration|}} -
      -
      -

      {{registration.title}}

      -

      {{registration.category}}

      -

      {{moment-format registration.dateRegistered}}

      -

      - - View on OSF - - {{link-to 'Detail' 'registrations.detail' registration.id class="btn btn-primary"}} -

      -
      +
      +
      +

      {{registration.title}}

      +

      {{registration.category}}

      +

      {{moment-format registration.dateRegistered}}

      +

      + + View on OSF + + {{link-to 'Detail' 'registrations.detail' registration.id class="btn btn-primary"}} +

      +
      {{/each}} diff --git a/tests/dummy/app/templates/users/detail.hbs b/tests/dummy/app/templates/users/detail.hbs index e97af6244..a50af0de7 100644 --- a/tests/dummy/app/templates/users/detail.hbs +++ b/tests/dummy/app/templates/users/detail.hbs @@ -1,50 +1,50 @@ {{link-to 'Back to list' 'users' class="btn btn-default"}}
      -

      Data

      -

      {{model.fullName}}

      -

      {{moment-format model.dateRegistered}}

      -

      - - View on OSF - -

      -
      -

      Nodes

      - - - - - - {{#each model.nodes as |node|}} - - - - - {{/each}} -
      IDTitle
      {{node.id}}{{node.title}}
      -
      -

      Registrations

      - - - - - - {{#each model.registrations as |registration|}} - - - - - {{/each}} -
      IDTitle
      {{registration.id}}{{registration.title}}
      -
      -

      Affiliated Institutions

      -

      +

      Data

      +

      {{model.fullName}}

      +

      {{moment-format model.dateRegistered}}

      +

      + + View on OSF + +

      +
      +

      Nodes

      - {{#each model.affiliatedInstitutions as |inst|}} - {{inst.name}} + + - {{/each}} + {{#each model.nodes as |node|}} + + + + + {{/each}}
      IDTitle
      {{node.id}}{{node.title}}
      -

      +
      +

      Registrations

      + + + + + + {{#each model.registrations as |registration|}} + + + + + {{/each}} +
      IDTitle
      {{registration.id}}{{registration.title}}
      +
      +

      Affiliated Institutions

      +

      + + {{#each model.affiliatedInstitutions as |inst|}} + + {{inst.name}} + + {{/each}} +
      +

      diff --git a/tests/dummy/app/templates/users/index.hbs b/tests/dummy/app/templates/users/index.hbs index 3bda43461..0895efdbd 100644 --- a/tests/dummy/app/templates/users/index.hbs +++ b/tests/dummy/app/templates/users/index.hbs @@ -1,15 +1,15 @@

      Users


      {{#each model as |user|}} -
      -

      {{user.fullName}}

      -

      {{moment-format user.dateRegistered}}

      -
      -

      - - View on OSF - - {{link-to 'Detail' 'users.detail' user.id class="btn btn-primary"}} -

      -
      +
      +

      {{user.fullName}}

      +

      {{moment-format user.dateRegistered}}

      +
      +

      + + View on OSF + + {{link-to 'Detail' 'users.detail' user.id class="btn btn-primary"}} +

      +
      {{/each}} From e7c678d7b530482ba84eb7f311b8705bdbcbcd70 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 20 May 2016 11:28:28 -0400 Subject: [PATCH 261/959] Remove line breaks. --- tests/dummy/app/templates/nodes/detail.hbs | 63 +++++++++++----------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 3062492e1..c57c69eaf 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -34,23 +34,22 @@

      - {{radio-button name="category" value="analysis" checked=editedCategory}} Analysis
      - {{radio-button name="category" value="communication" checked=editedCategory}} Communication
      - {{radio-button name="category" value="data" checked=editedCategory}} Data
      - {{radio-button name="category" value="hypothesis" checked=editedCategory}} Hypothesis
      - {{radio-button name="category" value="instrumentation" checked=editedCategory}} Instrumentation
      - {{radio-button name="category" value="methods and measures" checked=editedCategory}} Methods and Measures
      - {{radio-button name="category" value="procedure" checked=editedCategory}} Procedure
      - {{radio-button name="category" value="project" checked=editedCategory}} Project
      - {{radio-button name="category" value="software" checked=editedCategory}} Software
      - {{radio-button name="category" value="other" checked=editedCategory}} Other
      - {{radio-button name="category" value="uncategorized" checked=editedCategory}} Uncategorized
      +

      {{radio-button name="category" value="analysis" checked=editedCategory}} Analysis

      +

      {{radio-button name="category" value="communication" checked=editedCategory}} Communication

      +

      {{radio-button name="category" value="data" checked=editedCategory}} Data

      +

      {{radio-button name="category" value="hypothesis" checked=editedCategory}} Hypothesis

      +

      {{radio-button name="category" value="instrumentation" checked=editedCategory}} Instrumentation

      +

      {{radio-button name="category" value="methods and measures" checked=editedCategory}} Methods and Measures

      +

      {{radio-button name="category" value="procedure" checked=editedCategory}} Procedure

      +

      {{radio-button name="category" value="project" checked=editedCategory}} Project

      +

      {{radio-button name="category" value="software" checked=editedCategory}} Software

      +

      {{radio-button name="category" value="other" checked=editedCategory}} Other

      +

      {{radio-button name="category" value="uncategorized" checked=editedCategory}} Uncategorized

      -

      - {{radio-button name="isPublic" value=1 checked=isPublic}} Public
      - {{radio-button name="isPublic" value=0 checked=isPublic}} Private
      + {{radio-button name="isPublic" value=1 checked=isPublic}} Public + {{radio-button name="isPublic" value=0 checked=isPublic}} Private {{else}} @@ -94,24 +93,24 @@

      Create component

      - - {{input type="text" value=title placeholder="Component's title" required=true}}
      - - {{input type="text" value=description placeholder="Component's description"}}
      -
      - {{radio-button name="category" value="analysis" checked=category}} Analysis
      - {{radio-button name="category" value="communication" checked=category}} Communication
      - {{radio-button name="category" value="data" checked=category}} Data
      - {{radio-button name="category" value="hypothesis" checked=category}} Hypothesis
      - {{radio-button name="category" value="instrumentation" checked=category}} Instrumentation
      - {{radio-button name="category" value="methods and measures" checked=category}} Methods and Measures
      - {{radio-button name="category" value="procedure" checked=category}} Procedure
      - {{radio-button name="category" value="project" checked=category}} Project
      - {{radio-button name="category" value="software" checked=category}} Software
      - {{radio-button name="category" value="other" checked=category}} Other
      - {{radio-button name="category" value="uncategorized" checked=category}} Uncategorized
      -
      -

      + + {{input type="text" value=title placeholder="Component's title" required=true}} + + {{input type="text" value=description placeholder="Component's description"}} +

      +

      {{radio-button name="category" value="analysis" checked=category}} Analysis

      +

      {{radio-button name="category" value="communication" checked=category}} Communication

      +

      {{radio-button name="category" value="data" checked=category}} Data

      +

      {{radio-button name="category" value="hypothesis" checked=category}} Hypothesis

      +

      {{radio-button name="category" value="instrumentation" checked=category}} Instrumentation

      +

      {{radio-button name="category" value="methods and measures" checked=category}} Methods and Measures

      +

      {{radio-button name="category" value="procedure" checked=category}} Procedure

      +

      {{radio-button name="category" value="project" checked=category}} Project

      +

      {{radio-button name="category" value="software" checked=category}} Software

      +

      {{radio-button name="category" value="other" checked=category}} Other

      +

      {{radio-button name="category" value="uncategorized" checked=category}} Uncategorized

      + +

      From 227c12529db7730c5082784c261fce775b20a7ac Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Fri, 20 May 2016 11:43:23 -0400 Subject: [PATCH 262/959] Clean up templates. --- package.json | 181 +++++++++--------- .../app/components/log-detail/template.hbs | 30 +-- tests/dummy/app/templates/nodes/detail.hbs | 100 ++++------ 3 files changed, 147 insertions(+), 164 deletions(-) diff --git a/package.json b/package.json index e84d76642..d926dcab2 100644 --- a/package.json +++ b/package.json @@ -1,93 +1,94 @@ { - "name": "ember-osf", - "version": "0.0.1", - "description": "Ember Data models for the OSF APIv2", - "directories": { - "doc": "doc", - "test": "tests" - }, - "scripts": { - "build": "ember build", - "start": "ember server", - "test": "ember test", - "check-style": "./node_modules/jscs/bin/jscs ." - }, - "repository": "", - "engines": { - "node": ">= 0.10.0" - }, - "author": "", - "license": "MIT", - "devDependencies": { - "broccoli-asset-rev": "^2.2.0", - "chalk": "^1.1.3", - "ember-a11y": "0.1.8", - "ember-a11y-testing": "0.0.5", - "ember-ajax": "0.7.1", - "ember-cli": "^2.4.3", - "ember-cli-app-version": "^1.0.0", - "ember-cli-bootstrap-sassy": "0.5.3", - "ember-cli-dependency-checker": "^1.2.0", - "ember-cli-inject-live-reload": "^1.3.1", - "ember-cli-mirage": "0.1.13", - "ember-cli-qunit": "^1.2.1", - "ember-cli-release": "0.2.8", - "ember-cli-sass": "5.3.1", - "ember-cli-sri": "^2.0.0", - "ember-cli-template-lint": "0.4.7", - "ember-cli-uglify": "^1.2.0", - "ember-component-css": "0.1.9", - "ember-data": "^2.3.0", - "ember-disable-prototype-extensions": "^1.0.0", - "ember-disable-proxy-controllers": "^1.0.1", - "ember-export-application-global": "^1.0.4", - "ember-i18n": "4.2.1", - "ember-load-initializers": "0.5.1", - "ember-resolver": "2.0.3", - "ember-sinon": "0.5.0", - "ember-sinon-qunit": "1.3.1", - "jscs": "^3.0.3", - "loader": "2.1.0", - "loader.js": "4.0.3", - "moment": "^2.13.0" - }, - "keywords": [ - "ember-addon" + "name": "ember-osf", + "version": "0.0.1", + "description": "Ember Data models for the OSF APIv2", + "directories": { + "doc": "doc", + "test": "tests" + }, + "scripts": { + "build": "ember build", + "start": "ember server", + "test": "ember test", + "check-style": "./node_modules/jscs/bin/jscs ." + }, + "repository": "", + "engines": { + "node": ">= 0.10.0" + }, + "author": "", + "license": "MIT", + "devDependencies": { + "broccoli-asset-rev": "^2.2.0", + "chalk": "^1.1.3", + "ember-a11y": "0.1.8", + "ember-a11y-testing": "0.0.5", + "ember-ajax": "0.7.1", + "ember-cli": "^2.4.3", + "ember-cli-app-version": "^1.0.0", + "ember-cli-bootstrap-sassy": "0.5.3", + "ember-cli-dependency-checker": "^1.2.0", + "ember-cli-inject-live-reload": "^1.3.1", + "ember-cli-mirage": "0.1.13", + "ember-cli-qunit": "^1.2.1", + "ember-cli-release": "0.2.8", + "ember-cli-sass": "5.3.1", + "ember-cli-sri": "^2.0.0", + "ember-cli-template-lint": "0.4.7", + "ember-cli-uglify": "^1.2.0", + "ember-component-css": "0.1.9", + "ember-data": "^2.3.0", + "ember-disable-prototype-extensions": "^1.0.0", + "ember-disable-proxy-controllers": "^1.0.1", + "ember-export-application-global": "^1.0.4", + "ember-i18n": "4.2.1", + "ember-load-initializers": "0.5.1", + "ember-resolver": "2.0.3", + "ember-sinon": "0.5.0", + "ember-sinon-qunit": "1.3.1", + "jscs": "^3.0.3", + "loader": "2.1.0", + "loader.js": "4.0.3", + "moment": "^2.13.0" + }, + "keywords": [ + "ember-addon" + ], + "dependencies": { + "config": "^1.20.1", + "ember-cli-babel": "^5.1.5", + "ember-cli-htmlbars": "^1.0.1", + "ember-cli-htmlbars-inline-precompile": "^0.3.1", + "ember-cli-moment-shim": "1.1.0", + "ember-cli-node-assets": "^0.1.3", + "ember-get-config": "0.0.2", + "ember-moment": "6.1.0", + "ember-radio-buttons": "^4.0.1", + "ember-simple-auth": "1.1.0-beta.5", + "js-yaml": "^3.6.0" + }, + "ember-addon": { + "configPath": "tests/dummy/config" + }, + "jscsConfig": { + "preset": "airbnb", + "excludeFiles": [ + "bower_components", + "dist", + "tmp", + "vendor", + "app/locales", + "tests/unit", + "tests/integration", + "tests/helpers", + "tests/dummy/app/mirage" ], - "dependencies": { - "config": "^1.20.1", - "ember-cli-babel": "^5.1.5", - "ember-cli-htmlbars": "^1.0.1", - "ember-cli-htmlbars-inline-precompile": "^0.3.1", - "ember-cli-moment-shim": "1.1.0", - "ember-cli-node-assets": "^0.1.3", - "ember-get-config": "0.0.2", - "ember-moment": "6.1.0", - "ember-simple-auth": "1.1.0-beta.5", - "js-yaml": "^3.6.0" - }, - "ember-addon": { - "configPath": "tests/dummy/config" - }, - "jscsConfig": { - "preset": "airbnb", - "excludeFiles": [ - "bower_components", - "dist", - "tmp", - "vendor", - "app/locales", - "tests/unit", - "tests/integration", - "tests/helpers", - "tests/dummy/app/mirage" - ], - "requireSpacesInAnonymousFunctionExpression": false, - "requireTrailingComma": false, - "disallowTrailingComma": false, - "requirePaddingNewLinesAfterBlocks": false, - "validateIndentation": 4, - "requirePaddingNewLinesBeforeLineComments": false, - "maximumLineLength": false - } + "requireSpacesInAnonymousFunctionExpression": false, + "requireTrailingComma": false, + "disallowTrailingComma": false, + "requirePaddingNewLinesAfterBlocks": false, + "validateIndentation": 4, + "requirePaddingNewLinesBeforeLineComments": false, + "maximumLineLength": false + } } diff --git a/tests/dummy/app/components/log-detail/template.hbs b/tests/dummy/app/components/log-detail/template.hbs index 0d7f7ecc0..0b08beede 100644 --- a/tests/dummy/app/components/log-detail/template.hbs +++ b/tests/dummy/app/components/log-detail/template.hbs @@ -10,19 +10,19 @@ Additional Params Included {{#each node-logs as |node-log|}} - - {{node-log.action}} - {{node-log.originalNode.title}}: {{node-log.originalNode.id}} - {{node-log.user.givenName}} - {{node-log.node.title}}: {{node-log.node.id}} - {{moment-format node-log.date}} - - {{#each-in node-log.params as |key value|}} - {{key}}, - {{/each-in}} - {{if node-log.linkedNode "linked_node"}} - {{if node-log.templateNode "template_node"}} - - - {{/each}} + + {{node-log.action}} + {{node-log.originalNode.title}}: {{node-log.originalNode.id}} + {{node-log.user.givenName}} + {{node-log.node.title}}: {{node-log.node.id}} + {{moment-format node-log.date}} + + {{#each-in node-log.params as |key value|}} + {{key}}, + {{/each-in}} + {{if node-log.linkedNode "linked_node"}} + {{if node-log.templateNode "template_node"}} + + + {{/each}}x diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index ea51fdeaf..e5693ef45 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -18,57 +18,39 @@
      {{#if propertiesVisible}} - - - - - - - - - - - -
      {{input value=editedTitle}}
      {{input value=editedDescription}}
      - -

      -
      -

      {{radio-button name="category" value="analysis" checked=editedCategory}} Analysis

      -

      {{radio-button name="category" value="communication" checked=editedCategory}} Communication

      -

      {{radio-button name="category" value="data" checked=editedCategory}} Data

      -

      {{radio-button name="category" value="hypothesis" checked=editedCategory}} Hypothesis

      -

      {{radio-button name="category" value="instrumentation" checked=editedCategory}} Instrumentation

      -

      {{radio-button name="category" value="methods and measures" checked=editedCategory}} Methods and Measures

      -

      {{radio-button name="category" value="procedure" checked=editedCategory}} Procedure

      -

      {{radio-button name="category" value="project" checked=editedCategory}} Project

      -

      {{radio-button name="category" value="software" checked=editedCategory}} Software

      -

      {{radio-button name="category" value="other" checked=editedCategory}} Other

      -

      {{radio-button name="category" value="uncategorized" checked=editedCategory}} Uncategorized

      -
      - -

      - {{radio-button name="isPublic" value=1 checked=isPublic}} Public - {{radio-button name="isPublic" value=0 checked=isPublic}} Private + + + + + + + + + + +
      {{input value=editedTitle}}
      {{input value=editedDescription}}
      +

      +
      +

      {{radio-button name="category" value="analysis" checked=editedCategory}} Analysis

      +

      {{radio-button name="category" value="communication" checked=editedCategory}} Communication

      +

      {{radio-button name="category" value="data" checked=editedCategory}} Data

      +

      {{radio-button name="category" value="hypothesis" checked=editedCategory}} Hypothesis

      +

      {{radio-button name="category" value="instrumentation" checked=editedCategory}} Instrumentation

      +

      {{radio-button name="category" value="methods and measures" checked=editedCategory}} Methods and Measures

      +

      {{radio-button name="category" value="procedure" checked=editedCategory}} Procedure

      +

      {{radio-button name="category" value="project" checked=editedCategory}} Project

      +

      {{radio-button name="category" value="software" checked=editedCategory}} Software

      +

      {{radio-button name="category" value="other" checked=editedCategory}} Other

      +

      {{radio-button name="category" value="uncategorized" checked=editedCategory}} Uncategorized

      +
      +

      + {{radio-button name="isPublic" value=1 checked=isPublic}} Public + {{radio-button name="isPublic" value=0 checked=isPublic}} Private - + {{else}} - {{/if}} -

      Contributors

      - - - - - - - {{#each model.contributors as |contrib|}} - - - - - {{/each}} -
      IDAuthor?
      {{contrib.id}}{{contrib.bibliographic}}

      Contributors

      @@ -83,6 +65,7 @@ {{/each}}
      +

      @@ -108,20 +91,19 @@ {{input type="text" value=description placeholder="Component's description"}}

      -

      {{radio-button name="category" value="analysis" checked=category}} Analysis

      -

      {{radio-button name="category" value="communication" checked=category}} Communication

      -

      {{radio-button name="category" value="data" checked=category}} Data

      -

      {{radio-button name="category" value="hypothesis" checked=category}} Hypothesis

      -

      {{radio-button name="category" value="instrumentation" checked=category}} Instrumentation

      -

      {{radio-button name="category" value="methods and measures" checked=category}} Methods and Measures

      -

      {{radio-button name="category" value="procedure" checked=category}} Procedure

      -

      {{radio-button name="category" value="project" checked=category}} Project

      -

      {{radio-button name="category" value="software" checked=category}} Software

      -

      {{radio-button name="category" value="other" checked=category}} Other

      -

      {{radio-button name="category" value="uncategorized" checked=category}} Uncategorized

      +

      {{radio-button name="category" value="analysis" checked=category}} Analysis

      +

      {{radio-button name="category" value="communication" checked=category}} Communication

      +

      {{radio-button name="category" value="data" checked=category}} Data

      +

      {{radio-button name="category" value="hypothesis" checked=category}} Hypothesis

      +

      {{radio-button name="category" value="instrumentation" checked=category}} Instrumentation

      +

      {{radio-button name="category" value="methods and measures" checked=category}} Methods and Measures

      +

      {{radio-button name="category" value="procedure" checked=category}} Procedure

      +

      {{radio-button name="category" value="project" checked=category}} Project

      +

      {{radio-button name="category" value="software" checked=category}} Software

      +

      {{radio-button name="category" value="other" checked=category}} Other

      +

      {{radio-button name="category" value="uncategorized" checked=category}} Uncategorized

      - {{outlet}} From eaf3b5461ae240b23960540c4f6055d860f11252 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 12:12:41 -0400 Subject: [PATCH 263/959] Consistent 2-space indentation --- .../app/components/file-actions/template.hbs | 160 +++++++++--------- .../app/components/file-tree/template.hbs | 38 ++--- .../app/templates/nodes/detail/files.hbs | 2 +- .../templates/nodes/detail/files/index.hbs | 8 +- .../nodes/detail/files/provider/index.hbs | 26 +-- .../app/templates/nodes/detail/index.hbs | 8 +- tests/dummy/app/templates/signup.hbs | 10 +- tests/dummy/app/templates/users/list.hbs | 10 +- 8 files changed, 131 insertions(+), 131 deletions(-) diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index 51dc89ac0..8a83fba5f 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -1,82 +1,82 @@
      - {{#unless file.isProvider}} - - - - - - - - - - - - - - - {{/unless}} - {{#if file.isFolder}} - - - - - - - - - - {{else}} - - - - - - - - {{/if}} + {{#unless file.isProvider}} + + + + + + + + + + + + + + + {{/unless}} + {{#if file.isFolder}} + + + + + + + + + + {{else}} + + + + + + + + {{/if}}
      - Rename: - - {{input value=newName}} - - -
      - Delete: - - -
      - Move to: - -
      Folder ID: {{input value=moveTarget}}
      -
      Node ID (optional): {{input value=moveNode}}
      -
      New name (optional): {{input value=moveName}}
      -
      -
      -
      - -
      - New folder: - - {{input value=newFolderName}} - - -
      - Upload file: - - {{input type='file' change=(action 'uploadFile')}} -
      - -
      - Update file contents: - - {{input type='file' change=(action 'updateContents')}} -
      + Rename: + + {{input value=newName}} + + +
      + Delete: + + +
      + Move to: + +
      Folder ID: {{input value=moveTarget}}
      +
      Node ID (optional): {{input value=moveNode}}
      +
      New name (optional): {{input value=moveName}}
      +
      +
      +
      + +
      + New folder: + + {{input value=newFolderName}} + + +
      + Upload file: + + {{input type='file' change=(action 'uploadFile')}} +
      + +
      + Update file contents: + + {{input type='file' change=(action 'updateContents')}} +
      diff --git a/tests/dummy/app/components/file-tree/template.hbs b/tests/dummy/app/components/file-tree/template.hbs index 9330ce1a3..f6cddb194 100644 --- a/tests/dummy/app/components/file-tree/template.hbs +++ b/tests/dummy/app/components/file-tree/template.hbs @@ -1,23 +1,23 @@

      - {{#if onClickFile}} - {{root.name}} + {{#if onClickFile}} + {{root.name}} + {{else}} + {{#if root.isProvider}} + {{link-to root.name 'nodes.detail.files.provider' node root}} {{else}} - {{#if root.isProvider}} - {{link-to root.name 'nodes.detail.files.provider' node root}} - {{else}} - {{link-to root.name 'nodes.detail.files.provider.file' - node root.provider root}} - {{/if}} - {{/if}} - {{#if root.isFolder}} -
        - {{#each root.files as |file|}} -
      • - {{file-tree root=file node=node}} -
      • - {{else}} -
      • (empty folder)
      • - {{/each}} -
      + {{link-to root.name 'nodes.detail.files.provider.file' + node root.provider root}} {{/if}} + {{/if}} + {{#if root.isFolder}} +
        + {{#each root.files as |file|}} +
      • + {{file-tree root=file node=node}} +
      • + {{else}} +
      • (empty folder)
      • + {{/each}} +
      + {{/if}}
      diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs index 1ce4e8a27..46ac22ac5 100644 --- a/tests/dummy/app/templates/nodes/detail/files.hbs +++ b/tests/dummy/app/templates/nodes/detail/files.hbs @@ -1,5 +1,5 @@
      - {{link-to 'Back to node' 'nodes.detail' node class='btn btn-primary'}} + {{link-to 'Back to node' 'nodes.detail' node class='btn btn-primary'}}
      {{outlet}} diff --git a/tests/dummy/app/templates/nodes/detail/files/index.hbs b/tests/dummy/app/templates/nodes/detail/files/index.hbs index 7a6bcdee1..aa50f8777 100644 --- a/tests/dummy/app/templates/nodes/detail/files/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/index.hbs @@ -1,6 +1,6 @@
      -

      Files

      - {{#each model as |provider|}} - {{file-tree root=provider node=provider.node}} - {{/each}} +

      Files

      + {{#each model as |provider|}} + {{file-tree root=provider node=provider.node}} + {{/each}}
      diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs index df20475ae..276e3d40f 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs @@ -1,18 +1,18 @@
      -
      - {{link-to 'Back to providers' 'nodes.detail.files' - model.node class='btn'}} -
      -

      {{model.name}}

      -

      {{model.id}}

      -

      {{model.provider}}

      -

      {{model.path}}

      +
      + {{link-to 'Back to providers' 'nodes.detail.files' + model.node class='btn'}} +
      +

      {{model.name}}

      +

      {{model.id}}

      +

      {{model.provider}}

      +

      {{model.path}}

      -

      Files

      - {{file-tree root=model node=model.node}} +

      Files

      + {{file-tree root=model node=model.node}} -
      +
      -

      Actions

      - {{file-actions file=model onChange=(action 'reloadFiles')}} +

      Actions

      + {{file-actions file=model onChange=(action 'reloadFiles')}}
      diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index db2b95b4c..5a9703ab5 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -31,14 +31,14 @@

      {{#each model.affiliatedInstitutions as |inst|}} - - {{inst.name}} - + + {{inst.name}} + {{/each}}

      Files

      - {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}} + {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}}
      {{log-detail node-logs=model.logs}}
      diff --git a/tests/dummy/app/templates/signup.hbs b/tests/dummy/app/templates/signup.hbs index 47d12fd68..4fba57d38 100644 --- a/tests/dummy/app/templates/signup.hbs +++ b/tests/dummy/app/templates/signup.hbs @@ -1,8 +1,8 @@
      {{#login-form}}{{/login-form}} -
      -
      - {{#sign-up}}{{/sign-up}} -
      -
      \ No newline at end of file +
    +
    + {{#sign-up}}{{/sign-up}} +
    +
    diff --git a/tests/dummy/app/templates/users/list.hbs b/tests/dummy/app/templates/users/list.hbs index 2dab41947..7113bd9d2 100644 --- a/tests/dummy/app/templates/users/list.hbs +++ b/tests/dummy/app/templates/users/list.hbs @@ -2,11 +2,11 @@

    {{pagination-control - currentPage=page - pageCount=totalPages - next=(action 'next') - previous=(action 'previous') - goToPage=(action 'goToPage') + currentPage=page + pageCount=totalPages + next=(action 'next') + previous=(action 'previous') + goToPage=(action 'goToPage') }}

    From 89a7280bc033c6211bca808e235f932ea1a9312a Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 12:17:29 -0400 Subject: [PATCH 264/959] Fix template linting errors --- .../app/components/file-actions/template.hbs | 29 ++++++++++++------- .../nodes/detail/files/provider/index.hbs | 2 +- tests/dummy/app/templates/signup.hbs | 10 +++---- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index 8a83fba5f..dd08e979d 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -9,7 +9,8 @@ + Rename + @@ -18,7 +19,8 @@ + Delete + @@ -29,16 +31,21 @@
    Folder ID: {{input value=moveTarget}}
    Node ID (optional): {{input value=moveNode}}
    New name (optional): {{input value=moveName}}
    -
    +
    + Move + {{/unless}} @@ -51,8 +58,9 @@ {{input value=newFolderName}} - + @@ -67,7 +75,8 @@ + Download + diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs index 276e3d40f..26004eb51 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs @@ -11,7 +11,7 @@

    Files

    {{file-tree root=model node=model.node}} -
    +

    Actions

    {{file-actions file=model onChange=(action 'reloadFiles')}} diff --git a/tests/dummy/app/templates/signup.hbs b/tests/dummy/app/templates/signup.hbs index 4fba57d38..ff1dce692 100644 --- a/tests/dummy/app/templates/signup.hbs +++ b/tests/dummy/app/templates/signup.hbs @@ -1,8 +1,8 @@
    {{#login-form}}{{/login-form}} -
    -
    - {{#sign-up}}{{/sign-up}} -
    -
    +
    +
    + {{#sign-up}}{{/sign-up}} +
    +
    From edf21ba42d94c4df84ebbc48864987898b8c632f Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 12:19:57 -0400 Subject: [PATCH 265/959] Change indent_size in .editorconfig --- .editorconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index cec8c9204..3ef6636ee 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,7 +20,7 @@ indent_size = 4 [*.hbs] insert_final_newline = false indent_style = space -indent_size = 2 +indent_size = 4 [*.css] indent_style = space @@ -28,7 +28,7 @@ indent_size = 4 [*.html] indent_style = space -indent_size = 2 +indent_size = 4 [*.{diff,md}] trim_trailing_whitespace = false From 7f03210b41b6e46d56d4ef28eba8f8a2038a7d0b Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 12:58:10 -0400 Subject: [PATCH 266/959] Comment formatting [skip ci] --- addon/services/file-manager.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index f5d3e3fff..7f2831c22 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -18,7 +18,9 @@ export default Ember.Service.extend({ // after you create a file, you should go get a cup of coffee, come back, // and hard reload. - // File actions + + ///////////////////// File-only actions ///////////////////// + getContents(file) { let url = file.get('links').download; return this._waterbutlerRequest('GET', url); @@ -35,7 +37,9 @@ export default Ember.Service.extend({ // the only writable attribute on the file model. }, - // Folder actions + + ///////////////////// Folder-only actions ///////////////////// + addSubfolder(folder, name) { let url = folder.get('links').new_folder; let params = { @@ -60,7 +64,9 @@ export default Ember.Service.extend({ return this._waterbutlerRequest('PUT', url, params, contents); }, - // File and folder actions + + ///////////////////// File and folder actions ///////////////////// + rename(file, newName) { let url = file.get('links').move; let data = JSON.stringify({ action: 'rename', rename: newName }); @@ -119,6 +125,9 @@ export default Ember.Service.extend({ }); }, + + ///////////////////// Privates ///////////////////// + _waterbutlerRequest(method, url, queryParams=null, data=null) { if (queryParams) { let queryString = Ember.$.param(queryParams); @@ -136,9 +145,7 @@ export default Ember.Service.extend({ Authorization: `Bearer ${accessToken}` }, success: (data) => resolve(data), - error: (_, __, error) => { - reject(error); - } + error: (_, __, error) => reject(error) }); }); }, From 3b3ccd15ab28e2a931975fc49fbf69f95d1181f5 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 13:10:03 -0400 Subject: [PATCH 267/959] Minor code cleanup --- addon/services/file-manager.js | 4 ++-- tests/dummy/app/templates/users/list.hbs | 10 +++++----- tests/unit/services/file-manager-test.js | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index 7f2831c22..bbde92a37 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -77,7 +77,7 @@ export default Ember.Service.extend({ }, move(file, targetFolder, { newName=null, replace=true, - node=null, provider=null, copy=false }) { + node=null, provider=null, copy=false } = {}) { let url = file.get('links').move; let data = { action: copy ? 'copy' : 'move', @@ -109,7 +109,7 @@ export default Ember.Service.extend({ }, copy(file, targetFolder, { newName=null, replace=true, - node=null, provider=null }) { + node=null, provider=null } = {}) { return this.move(file, targetFolder, { newName, replace, node, provider, copy: true }); }, diff --git a/tests/dummy/app/templates/users/list.hbs b/tests/dummy/app/templates/users/list.hbs index 7113bd9d2..2dab41947 100644 --- a/tests/dummy/app/templates/users/list.hbs +++ b/tests/dummy/app/templates/users/list.hbs @@ -2,11 +2,11 @@

    {{pagination-control - currentPage=page - pageCount=totalPages - next=(action 'next') - previous=(action 'previous') - goToPage=(action 'goToPage') + currentPage=page + pageCount=totalPages + next=(action 'next') + previous=(action 'previous') + goToPage=(action 'goToPage') }}

    diff --git a/tests/unit/services/file-manager-test.js b/tests/unit/services/file-manager-test.js index cbfe43d46..c1612d7d9 100644 --- a/tests/unit/services/file-manager-test.js +++ b/tests/unit/services/file-manager-test.js @@ -342,7 +342,7 @@ test('move sends valid waterbutler request', function(assert) { }; setupAjax(assert, request, response); - service.move(file, folder, {}).then(function(movedFile) { + service.move(file, folder).then(function(movedFile) { assert.equal(movedFile.get('id'), file.get('id')); done(); }).catch(function() { @@ -374,7 +374,7 @@ test('move passes along error', function(assert) { }; setupAjax(assert, request, response); - service.move(file, folder, {}).then(function() { + service.move(file, folder).then(function() { done(); }).catch(function(error) { assert.equal(error, response.statusText); @@ -411,7 +411,7 @@ test('copy sends valid waterbutler request', function(assert) { }; setupAjax(assert, request, response); - service.copy(file, folder, {}).then(function() { + service.copy(file, folder).then(function() { assert.ok(true); done(); }).catch(function() { @@ -443,7 +443,7 @@ test('copy passes along error', function(assert) { }; setupAjax(assert, request, response); - service.copy(file, folder, {}).then(function() { + service.copy(file, folder).then(function() { done(); }).catch(function(error) { assert.equal(error, response.statusText); From 60722ad769d37bf4c36a3fb77d579e957d09c828 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Thu, 19 May 2016 17:12:31 -0400 Subject: [PATCH 268/959] Move comment component out of dummy app Also add ability to edit comments. --- addon/components/comment-detail/component.js | 13 +++++++++++++ addon/components/comment-detail/template.hbs | 6 ++++++ app/components/comment-detail/component.js | 1 + .../app/components/comment-detail/component.js | 6 ------ .../app/components/comment-detail/template.hbs | 4 ---- .../components/comment-detail/component-test.js | 17 +++++++++++++++++ 6 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 addon/components/comment-detail/component.js create mode 100644 addon/components/comment-detail/template.hbs create mode 100644 app/components/comment-detail/component.js delete mode 100644 tests/dummy/app/components/comment-detail/component.js delete mode 100644 tests/dummy/app/components/comment-detail/template.hbs create mode 100644 tests/integration/components/comment-detail/component-test.js diff --git a/addon/components/comment-detail/component.js b/addon/components/comment-detail/component.js new file mode 100644 index 000000000..16241dca4 --- /dev/null +++ b/addon/components/comment-detail/component.js @@ -0,0 +1,13 @@ +import Ember from 'ember'; +import layout from './template'; + +export default Ember.Component.extend({ + layout, + + actions: { + editedComment(comment, content) { + comment.set('content', content); + comment.save(); + } + } +}); diff --git a/addon/components/comment-detail/template.hbs b/addon/components/comment-detail/template.hbs new file mode 100644 index 000000000..9d60448d6 --- /dev/null +++ b/addon/components/comment-detail/template.hbs @@ -0,0 +1,6 @@ +
  • +
    + {{input value=model.content}} +
    +
  • +{{yield}} diff --git a/app/components/comment-detail/component.js b/app/components/comment-detail/component.js new file mode 100644 index 000000000..101281f14 --- /dev/null +++ b/app/components/comment-detail/component.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/comment-detail/component'; diff --git a/tests/dummy/app/components/comment-detail/component.js b/tests/dummy/app/components/comment-detail/component.js deleted file mode 100644 index 8ef0d629f..000000000 --- a/tests/dummy/app/components/comment-detail/component.js +++ /dev/null @@ -1,6 +0,0 @@ -import Ember from 'ember'; -import layout from './template'; - -export default Ember.Component.extend({ - layout -}); diff --git a/tests/dummy/app/components/comment-detail/template.hbs b/tests/dummy/app/components/comment-detail/template.hbs deleted file mode 100644 index 142414d6c..000000000 --- a/tests/dummy/app/components/comment-detail/template.hbs +++ /dev/null @@ -1,4 +0,0 @@ -
  • -
    {{model.content}}
    -
  • -{{yield}} diff --git a/tests/integration/components/comment-detail/component-test.js b/tests/integration/components/comment-detail/component-test.js new file mode 100644 index 000000000..ac8765ad1 --- /dev/null +++ b/tests/integration/components/comment-detail/component-test.js @@ -0,0 +1,17 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('comment-detail', 'Integration | Component | comment detail', { + integration: true +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + this.set('comment', {'dateCreated': '05-19-2016', 'content': 'hello'}); + this.render(hbs`{{comment-detail model=comment}}`); + + assert.ok(this.$('div:contains("05-19-2016")')); + assert.ok(this.$('input[value=hello]')); + +}); From 2d1d19e3ba371533ebaffe3a83bc82b8afa950bf Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 13:36:10 -0400 Subject: [PATCH 269/959] Style fixes --- addon/services/file-manager.js | 49 ++++++++++++++++------------------ tests/dummy/app/router.js | 14 +++++----- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/addon/services/file-manager.js b/addon/services/file-manager.js index bbde92a37..a2ac0dd55 100644 --- a/addon/services/file-manager.js +++ b/addon/services/file-manager.js @@ -18,7 +18,6 @@ export default Ember.Service.extend({ // after you create a file, you should go get a cup of coffee, come back, // and hard reload. - ///////////////////// File-only actions ///////////////////// getContents(file) { @@ -37,7 +36,6 @@ export default Ember.Service.extend({ // the only writable attribute on the file model. }, - ///////////////////// Folder-only actions ///////////////////// addSubfolder(folder, name) { @@ -64,54 +62,54 @@ export default Ember.Service.extend({ return this._waterbutlerRequest('PUT', url, params, contents); }, - ///////////////////// File and folder actions ///////////////////// rename(file, newName) { let url = file.get('links').move; let data = JSON.stringify({ action: 'rename', rename: newName }); let p = this._waterbutlerRequest('POST', url, null, data); - return p.then((data) => { - return this._pushToStore(data, file.get('id')); - }); + return p.then((data) => this._pushToStore(data, file.get('id'))); }, - move(file, targetFolder, { newName=null, replace=true, - node=null, provider=null, copy=false } = {}) { + move(file, targetFolder, options = {}) { + // Default options: + // newName: null + // replace: true + // node: null + // provider: null + // copy: false + let url = file.get('links').move; let data = { - action: copy ? 'copy' : 'move', + action: options.copy ? 'copy' : 'move', path: targetFolder.get('path'), - conflict: replace ? 'replace' : 'keep' + conflict: options.replace === false ? 'keep' : 'replace' }; - if (newName) { - data.rename = newName; + if (options.newName) { + data.rename = options.newName; } - if (node) { - if (typeof node === 'string') { - data.resource = node; + if (options.node) { + if (typeof options.node === 'string') { + data.resource = options.node; } else { - data.resource = node.get('id'); + data.resource = options.node.get('id'); } } - if (provider) { - data.provider = provider; + if (options.provider) { + data.provider = options.provider; } let p = this._waterbutlerRequest('POST', url, null, JSON.stringify(data)); return p.then((data) => { - if (copy) { - // TODO get new file's info from OSF - } else { + if (!options.copy) { return this._pushToStore(data, file.get('id'), targetFolder); } }); }, - copy(file, targetFolder, { newName=null, replace=true, - node=null, provider=null } = {}) { - return this.move(file, targetFolder, - { newName, replace, node, provider, copy: true }); + copy(file, targetFolder, options={}) { + options.copy = true; + return this.move(file, targetFolder, options); }, deleteFile(file) { @@ -125,7 +123,6 @@ export default Ember.Service.extend({ }); }, - ///////////////////// Privates ///////////////////// _waterbutlerRequest(method, url, queryParams=null, data=null) { diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 377866336..90348562a 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -13,15 +13,15 @@ Router.map(function() { this.route('detail', { path: '/:node_id' }, function() { - this.route('files', function() { - this.route('provider', { - path: '/:provider' - }, function() { - this.route('file', { - path: '/:file_id' + this.route('files', function() { + this.route('provider', { + path: '/:provider' + }, function() { + this.route('file', { + path: '/:file_id' + }); }); }); - }); }); }); this.route('login'); From 0443cc4ff94ee0838c8c8ba723cac284487c919d Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 13:53:49 -0400 Subject: [PATCH 270/959] Do the right thing after moving a file in the dummy app --- tests/dummy/app/components/file-actions/component.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index 07021b726..17570e707 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -66,11 +66,10 @@ export default Ember.Component.extend({ moveFile(folderId) { let file = this.get('file'); let store = this.get('store'); - let folder = store.peekRecord('file', folderId); + let folder = store.findRecord('file', folderId); if (!folder) { - folder = store.peekRecord('file-provider', folderId); + folder = store.findRecord('file-provider', folderId); if (!folder) { - // TODO errors return; } } @@ -83,7 +82,7 @@ export default Ember.Component.extend({ }; let p = this.get('fileManager').move(file, folder, options); - p.then(() => this.get('onChange')); + p.then(() => this.get('onChange')()); } } }); From 312f546f447614b02b94ca32f8583bc54a5e6f2b Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 20 May 2016 14:01:32 -0400 Subject: [PATCH 271/959] Remove ember-radio-button --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index fe9a469f8..2c4ea2e5b 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "ember-export-application-global": "^1.0.4", "ember-i18n": "4.2.1", "ember-load-initializers": "0.5.1", - "ember-radio-button": "1.0.7", "ember-resolver": "2.0.3", "ember-sinon": "0.5.0", "ember-sinon-qunit": "1.3.1", From 0e0e418c4dbe33b10aee8a7c11740a9f04216676 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 20 May 2016 14:28:23 -0400 Subject: [PATCH 272/959] Fix bad indents --- addon/adapters/contributor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/adapters/contributor.js b/addon/adapters/contributor.js index 88b7ada2a..a112e1e55 100644 --- a/addon/adapters/contributor.js +++ b/addon/adapters/contributor.js @@ -2,7 +2,7 @@ import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ buildURL(_, __, snap) { - // TOOD: delete me when https://github.com/CenterForOpenScience/ember-osf/pull/34 is merged + // TOOD: delete me when https://github.com/CenterForOpenScience/ember-osf/pull/34 is merged // Modifies URL from /contributors to nodes//contributors/ to match APIv2 route for creating contributors. var base = this._super(...arguments); From fe572b1c0152d595af69669299ae1e2a179adf5d Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 14:31:40 -0400 Subject: [PATCH 273/959] 4-space indentation, hooray! --- addon/adapters/contributor.js | 2 +- .../app/components/file-actions/template.hbs | 178 +++++++++--------- .../app/components/file-tree/template.hbs | 38 ++-- .../app/templates/nodes/detail/files.hbs | 2 +- .../templates/nodes/detail/files/index.hbs | 8 +- .../nodes/detail/files/provider/file.hbs | 84 ++++----- .../nodes/detail/files/provider/index.hbs | 26 +-- .../app/templates/nodes/detail/index.hbs | 82 ++++---- 8 files changed, 210 insertions(+), 210 deletions(-) diff --git a/addon/adapters/contributor.js b/addon/adapters/contributor.js index 88b7ada2a..a112e1e55 100644 --- a/addon/adapters/contributor.js +++ b/addon/adapters/contributor.js @@ -2,7 +2,7 @@ import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ buildURL(_, __, snap) { - // TOOD: delete me when https://github.com/CenterForOpenScience/ember-osf/pull/34 is merged + // TOOD: delete me when https://github.com/CenterForOpenScience/ember-osf/pull/34 is merged // Modifies URL from /contributors to nodes//contributors/ to match APIv2 route for creating contributors. var base = this._super(...arguments); diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index dd08e979d..166d5ca11 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -1,91 +1,91 @@ - {{#unless file.isProvider}} - - - - - - - - - - - - - - - {{/unless}} - {{#if file.isFolder}} - - - - - - - - - - {{else}} - - - - - - - - {{/if}} + {{#unless file.isProvider}} + + + + + + + + + + + + + + + {{/unless}} + {{#if file.isFolder}} + + + + + + + + + + {{else}} + + + + + + + + {{/if}}
    - Rename: - - {{input value=newName}} - - -
    - Delete: - - -
    - Move to: - -
    Folder ID: {{input value=moveTarget}}
    -
    Node ID (optional): {{input value=moveNode}}
    -
    New name (optional): {{input value=moveName}}
    -
    - -
    -
    - -
    -
    - -
    - New folder: - - {{input value=newFolderName}} - - -
    - Upload file: - - {{input type='file' change=(action 'uploadFile')}} -
    - -
    - Update file contents: - - {{input type='file' change=(action 'updateContents')}} -
    + Rename: + + {{input value=newName}} + + +
    + Delete: + + +
    + Move to: + +
    Folder ID: {{input value=moveTarget}}
    +
    Node ID (optional): {{input value=moveNode}}
    +
    New name (optional): {{input value=moveName}}
    +
    + +
    +
    + +
    +
    + +
    + New folder: + + {{input value=newFolderName}} + + +
    + Upload file: + + {{input type='file' change=(action 'uploadFile')}} +
    + +
    + Update file contents: + + {{input type='file' change=(action 'updateContents')}} +
    diff --git a/tests/dummy/app/components/file-tree/template.hbs b/tests/dummy/app/components/file-tree/template.hbs index f6cddb194..62fc1b8d9 100644 --- a/tests/dummy/app/components/file-tree/template.hbs +++ b/tests/dummy/app/components/file-tree/template.hbs @@ -1,23 +1,23 @@
    - {{#if onClickFile}} - {{root.name}} - {{else}} - {{#if root.isProvider}} - {{link-to root.name 'nodes.detail.files.provider' node root}} + {{#if onClickFile}} + {{root.name}} {{else}} - {{link-to root.name 'nodes.detail.files.provider.file' - node root.provider root}} + {{#if root.isProvider}} + {{link-to root.name 'nodes.detail.files.provider' node root}} + {{else}} + {{link-to root.name 'nodes.detail.files.provider.file' + node root.provider root}} + {{/if}} + {{/if}} + {{#if root.isFolder}} +
      + {{#each root.files as |file|}} +
    • + {{file-tree root=file node=node}} +
    • + {{else}} +
    • (empty folder)
    • + {{/each}} +
    {{/if}} - {{/if}} - {{#if root.isFolder}} -
      - {{#each root.files as |file|}} -
    • - {{file-tree root=file node=node}} -
    • - {{else}} -
    • (empty folder)
    • - {{/each}} -
    - {{/if}}
    diff --git a/tests/dummy/app/templates/nodes/detail/files.hbs b/tests/dummy/app/templates/nodes/detail/files.hbs index 46ac22ac5..1ce4e8a27 100644 --- a/tests/dummy/app/templates/nodes/detail/files.hbs +++ b/tests/dummy/app/templates/nodes/detail/files.hbs @@ -1,5 +1,5 @@
    - {{link-to 'Back to node' 'nodes.detail' node class='btn btn-primary'}} + {{link-to 'Back to node' 'nodes.detail' node class='btn btn-primary'}}
    {{outlet}} diff --git a/tests/dummy/app/templates/nodes/detail/files/index.hbs b/tests/dummy/app/templates/nodes/detail/files/index.hbs index aa50f8777..7a6bcdee1 100644 --- a/tests/dummy/app/templates/nodes/detail/files/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/index.hbs @@ -1,6 +1,6 @@
    -

    Files

    - {{#each model as |provider|}} - {{file-tree root=provider node=provider.node}} - {{/each}} +

    Files

    + {{#each model as |provider|}} + {{file-tree root=provider node=provider.node}} + {{/each}}
    diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs index d32cd4546..b826d7fc1 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs @@ -1,48 +1,48 @@
    -
    - {{#link-to 'nodes.detail.files.provider' node model.provider class='btn'}} - Back to {{model.provider}} - {{/link-to}} -
    -

    {{model.kind}} detail: {{model.name}}

    -

    {{model.id}}

    -

    {{model.provider}}

    -

    {{model.path}}

    -

    {{model.materializedPath}}

    -

    {{model.lastTouched}}

    -

    {{model.dateModified}}

    -

    {{model.dateCreated}}

    -

    {{model.checkout}}

    +
    + {{#link-to 'nodes.detail.files.provider' node model.provider class='btn'}} + Back to {{model.provider}} + {{/link-to}} +
    +

    {{model.kind}} detail: {{model.name}}

    +

    {{model.id}}

    +

    {{model.provider}}

    +

    {{model.path}}

    +

    {{model.materializedPath}}

    +

    {{model.lastTouched}}

    +

    {{model.dateModified}}

    +

    {{model.dateCreated}}

    +

    {{model.checkout}}

    -
    +
    -

    Actions

    - {{file-actions file=model onChange=(action 'reloadFiles')}} +

    Actions

    + {{file-actions file=model onChange=(action 'reloadFiles')}} -
    - {{#if model.isFolder}} -

    Files

    - {{file-tree root=model node=node}} - {{else}} -

    Versions

    -
      - {{#each model.versions as |version|}} - {{file-version version=version}} - {{else}} - (none) - {{/each}} -

    -

    Comments

    -
      - {{#each model.comments as |comment|}} -
    • - - {{comment.content}} -
    • - {{else}} - (none) - {{/each}} -
    - {{/if}} + {{#if model.isFolder}} +

    Files

    + {{file-tree root=model node=node}} + {{else}} +

    Versions

    +
      + {{#each model.versions as |version|}} + {{file-version version=version}} + {{else}} + (none) + {{/each}} +
    +
    +

    Comments

    +
      + {{#each model.comments as |comment|}} +
    • + + {{comment.content}} +
    • + {{else}} + (none) + {{/each}} +
    + {{/if}}
    diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs index 26004eb51..2cee0ea68 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/index.hbs @@ -1,18 +1,18 @@
    -
    - {{link-to 'Back to providers' 'nodes.detail.files' - model.node class='btn'}} -
    -

    {{model.name}}

    -

    {{model.id}}

    -

    {{model.provider}}

    -

    {{model.path}}

    +
    + {{link-to 'Back to providers' 'nodes.detail.files' + model.node class='btn'}} +
    +

    {{model.name}}

    +

    {{model.id}}

    +

    {{model.provider}}

    +

    {{model.path}}

    -

    Files

    - {{file-tree root=model node=model.node}} +

    Files

    + {{file-tree root=model node=model.node}} -
    +
    -

    Actions

    - {{file-actions file=model onChange=(action 'reloadFiles')}} +

    Actions

    + {{file-actions file=model onChange=(action 'reloadFiles')}}
    diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index 9578c0c40..36c667eb3 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -1,46 +1,46 @@ {{link-to 'Back to list' 'nodes' class="btn btn-default"}}
    -

    Data

    -

    {{model.title}}

    -

    {{model.category}}

    -

    {{moment-format model.dateCreated}}

    -

    {{moment-format model.dateModified}}

    -

    - - View on OSF - -

    -
    -

    Edit this node

    - Title: {{input value=editedTitle}} - -

    Contributors

    - - - - - - {{#each model.contributors as |contrib|}} - - - - - {{/each}} -
    IDAuthor?
    {{contrib.id}}{{contrib.bibliographic}}
    - -

    +

    Data

    +

    {{model.title}}

    +

    {{model.category}}

    +

    {{moment-format model.dateCreated}}

    +

    {{moment-format model.dateModified}}

    +

    + + View on OSF + +

    +
    +

    Edit this node

    + Title: {{input value=editedTitle}} + +

    Contributors

    - {{#each model.affiliatedInstitutions as |inst|}} - {{inst.name}} + + - {{/each}} -
    IDAuthor?
    -

    -

    Files

    - {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}} -
    - {{log-detail node-logs=model.logs}} + {{#each model.contributors as |contrib|}} + + {{contrib.id}} + {{contrib.bibliographic}} + + {{/each}} + + +

    + + {{#each model.affiliatedInstitutions as |inst|}} + + {{inst.name}} + + {{/each}} +
    +

    +

    Files

    + {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}} +
    + {{log-detail node-logs=model.logs}}
    {{link-to 'Back to list' 'nodes' class="btn btn-default"}}
    @@ -78,9 +78,9 @@

    {{#each model.affiliatedInstitutions as |inst|}} - - {{inst.name}} - + + {{inst.name}} + {{/each}}

    From 88bd1cefa1f0e67af3c7273a8d0ed31df3d3891e Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 20 May 2016 14:35:42 -0400 Subject: [PATCH 274/959] This is embarassing... fix more indentation --- tests/dummy/app/templates/nodes/detail.hbs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index d1c6739d9..857997a51 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -34,9 +34,9 @@

    {{#each model.affiliatedInstitutions as |inst|}} - - {{inst.name}} - + + {{inst.name}} + {{/each}}

    From f65177b33a7b133c599829dc4de202071b52b62a Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Fri, 20 May 2016 14:45:49 -0400 Subject: [PATCH 275/959] Actually fix the indentation --- tests/dummy/app/templates/nodes/detail.hbs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail.hbs b/tests/dummy/app/templates/nodes/detail.hbs index 857997a51..13bb79425 100644 --- a/tests/dummy/app/templates/nodes/detail.hbs +++ b/tests/dummy/app/templates/nodes/detail.hbs @@ -36,9 +36,12 @@ {{#each model.affiliatedInstitutions as |inst|}} {{inst.name}} - + {{/each}}

    -

    Files

    {{#each model.files as |provider|}} {{files-tree model=provider}} {{/each}} +

    Files

    + {{#each model.files as |provider|}} + {{files-tree model=provider}} + {{/each}}
    From ab9323b87831e9d454f3c43972146064004367df Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Fri, 20 May 2016 16:31:07 -0400 Subject: [PATCH 276/959] Start on a file uploader widget [skip ci] --- addon/components/file-uploader/component.js | 53 +++++++++++++++++++ addon/components/file-uploader/style.css | 8 +++ addon/components/file-uploader/template.hbs | 18 +++++++ app/components/file-uploader/component.js | 1 + .../app/components/file-actions/template.hbs | 2 +- .../app/templates/nodes/detail/index.hbs | 46 +--------------- .../file-uploader/component-test.js | 24 +++++++++ 7 files changed, 107 insertions(+), 45 deletions(-) create mode 100644 addon/components/file-uploader/component.js create mode 100644 addon/components/file-uploader/style.css create mode 100644 addon/components/file-uploader/template.hbs create mode 100644 app/components/file-uploader/component.js create mode 100644 tests/integration/components/file-uploader/component-test.js diff --git a/addon/components/file-uploader/component.js b/addon/components/file-uploader/component.js new file mode 100644 index 000000000..bce42f79b --- /dev/null +++ b/addon/components/file-uploader/component.js @@ -0,0 +1,53 @@ +import Ember from 'ember'; +import layout from './template'; + +// TODO: Upload progress? + +export default Ember.Component.extend({ + layout, + fileManager: Ember.inject.service(), + classNames: ['file-uploader'], + classNameBindings: ['canDrop:valid-drop-zone'], + canDrop: false, + currentUploads: [], + errors: [], + + dragOver(event) { + if (event.dataTransfer.files.length) { + // Stop the event bubbling, so this can accept the drag/drop + return false; + } + }, + + dragEnter(event) { + if (event.dataTransfer.files.length) { + this.set('canDrop', true); + // Stop the event bubbling, so this can accept the drag/drop + return false; + } + }, + + dragLeave(event) { + this.set('canDrop', false); + }, + + drop(event) { + let fm = this.get('fileManager'); + let folder = this.get('uploadFolder'); + for (let file in event.dataTransfer.files) { + this.get('currentUploads').pushObject(file); + let p = fm.uploadFile(folder, file.name, file); + p.then(() => { + this.get('currentUploads').removeObject(file); + }).catch((error) => { + this.get('errors').pushObject(error); + this.get('currentUploads').removeObject(file); + }); + } + }, + + actions: { + fileUploaded() { + } + } +}); diff --git a/addon/components/file-uploader/style.css b/addon/components/file-uploader/style.css new file mode 100644 index 000000000..745f5c002 --- /dev/null +++ b/addon/components/file-uploader/style.css @@ -0,0 +1,8 @@ +.file-uploader { + height: 10em; + width: 10em; +} + +.valid-drop-zone { + border: 2px dashed blue; +} diff --git a/addon/components/file-uploader/template.hbs b/addon/components/file-uploader/template.hbs new file mode 100644 index 000000000..2959d088e --- /dev/null +++ b/addon/components/file-uploader/template.hbs @@ -0,0 +1,18 @@ +Drag a file here! +{{yield}} +{{#if currentUploads}} +

    Uploads

    +
      + {{#each currentUploads as |upload|}} +
    • {{upload.name}}
    • + {{/each}} +
    +{{/if}} +{{#if errors}} +

    Errors

    +
      + {{#each errors as |error|}} +
    • {{error}}
    • + {{/each}} +
    +{{/if}} diff --git a/app/components/file-uploader/component.js b/app/components/file-uploader/component.js new file mode 100644 index 000000000..0a7c77c79 --- /dev/null +++ b/app/components/file-uploader/component.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/file-uploader/component'; \ No newline at end of file diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index 166d5ca11..98ad802c7 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -68,7 +68,7 @@ Upload file: - {{input type='file' change=(action 'uploadFile')}} + {{file-uploader uploadFolder=file}} {{else}} diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index 36c667eb3..45879df17 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -1,48 +1,4 @@ {{link-to 'Back to list' 'nodes' class="btn btn-default"}} -
    -

    Data

    -

    {{model.title}}

    -

    {{model.category}}

    -

    {{moment-format model.dateCreated}}

    -

    {{moment-format model.dateModified}}

    -

    - - View on OSF - -

    -
    -

    Edit this node

    - Title: {{input value=editedTitle}} - -

    Contributors

    - - - - - - {{#each model.contributors as |contrib|}} - - - - - {{/each}} -
    IDAuthor?
    {{contrib.id}}{{contrib.bibliographic}}
    - -

    - - {{#each model.affiliatedInstitutions as |inst|}} - - {{inst.name}} - - {{/each}} -
    -

    -

    Files

    - {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}} -
    - {{log-detail node-logs=model.logs}} -
    -{{link-to 'Back to list' 'nodes' class="btn btn-default"}}

    Data

    {{model.title}}

    @@ -86,4 +42,6 @@

    Files

    {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}} +
    + {{log-detail node-logs=model.logs}}
    diff --git a/tests/integration/components/file-uploader/component-test.js b/tests/integration/components/file-uploader/component-test.js new file mode 100644 index 000000000..8f3da738f --- /dev/null +++ b/tests/integration/components/file-uploader/component-test.js @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('file-uploader', 'Integration | Component | file uploader', { + integration: true +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.render(hbs`{{file-uploader}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#file-uploader}} + template block text + {{/file-uploader}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); From f6de1b3df25df8cefaf13a205c331b07bed20bed Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Mon, 23 May 2016 11:14:47 -0400 Subject: [PATCH 277/959] fix buildurl for institutions, add affiliateNode, remove double node page work --- addon/adapters/osf-adapter.js | 2 +- tests/dummy/app/routes/nodes/detail.js | 2 +- .../app/templates/nodes/detail/index.hbs | 60 ++++--------------- 3 files changed, 14 insertions(+), 50 deletions(-) diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index 6a026f509..fc7347a9a 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -26,7 +26,7 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { } // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing // slash to URLs for single documents, but DRF redirects to force a trailing slash - if (url.lastIndexOf('/') !== 0) { + if (url.lastIndexOf('/') !== url.length - 1) { url += '/'; } return url; diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index c2c98c834..1a87bb6b2 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -39,7 +39,7 @@ export default Ember.Route.extend({ var node = this.modelFor(this.routeName); node.get('affiliatedInstitutions').removeObject(inst); node.save(); - } + }, addContributor(contribId, permission, bibliographic) { var node = this.modelFor(this.routeName); if (contribId) { diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index 4f01d5e7e..89c751d8a 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -1,49 +1,4 @@ {{link-to 'Back to list' 'nodes' class="btn btn-default"}} -
    -

    Data

    -

    {{model.title}}

    -

    {{model.category}}

    -

    {{moment-format model.dateCreated}}

    -

    {{moment-format model.dateModified}}

    -

    - - View on OSF - -

    -
    -

    Edit this node

    - Title: {{input value=editedTitle}} - -

    Contributors

    - - - - - - {{#each model.contributors as |contrib|}} - - - - - {{/each}} -
    IDAuthor?
    {{contrib.id}}{{contrib.bibliographic}}
    - -

    - - {{#each model.affiliatedInstitutions as |inst|}} - - {{inst.name}} - - - {{/each}} -
    -

    -

    Files

    - {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}} -
    - {{log-detail node-logs=model.logs}} -
    -{{link-to 'Back to list' 'nodes' class="btn btn-default"}}

    Data

    {{model.title}}

    @@ -75,17 +30,26 @@


    - + +

    Affiliated Institutions

    {{#each model.affiliatedInstitutions as |inst|}} + - + + + {{/each}}
    {{inst.name}} -
    + +
    +

    Add Institution

    + Institution Id {{input value=instId}} +

    +

    Files

    {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}}
    From 932857f93500fe06ce203ec602711188baed9cec Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 23 May 2016 12:23:07 -0400 Subject: [PATCH 278/959] Syntax. --- tests/dummy/app/controllers/nodes/detail.js | 2 ++ tests/dummy/app/routes/nodes/detail.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/dummy/app/controllers/nodes/detail.js b/tests/dummy/app/controllers/nodes/detail.js index f944ae088..4423f1dc6 100644 --- a/tests/dummy/app/controllers/nodes/detail.js +++ b/tests/dummy/app/controllers/nodes/detail.js @@ -19,4 +19,6 @@ export default Ember.Controller.extend({ var bibliographic = target.checked; var contributorId = target.value; this.editedBibliographic[contributorId] = bibliographic; + } + } }); diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index c06b65e53..103a25c22 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -60,7 +60,7 @@ export default Ember.Route.extend({ } } - } + }, attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic) { if (this.canModifyContributor(null, contribMap)) { From 3a5eaeab41e4e432895d7e245e9ded9f8626ee5e Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 23 May 2016 12:40:16 -0400 Subject: [PATCH 279/959] Move controller to nodes/detail/index.js. --- .../app/controllers/nodes/detail/index.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/dummy/app/controllers/nodes/detail/index.js diff --git a/tests/dummy/app/controllers/nodes/detail/index.js b/tests/dummy/app/controllers/nodes/detail/index.js new file mode 100644 index 000000000..4423f1dc6 --- /dev/null +++ b/tests/dummy/app/controllers/nodes/detail/index.js @@ -0,0 +1,24 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + editedPermissions: {}, + editedBibliographic: {}, + actions: { + expandProperties() { + this.toggleProperty('propertiesVisible'); + }, + permissionChange(permission) { + // Adds updated permissions for a certain contributor + var p = permission.split(' '); + var permissions = p[0]; + var contributorId = p[1]; + this.editedPermissions[contributorId] = permissions; + }, + bibliographicChange(target) { + // Adds updated bibliographic info for a certain contributor + var bibliographic = target.checked; + var contributorId = target.value; + this.editedBibliographic[contributorId] = bibliographic; + } + } +}); From ff62b831b7666278b3ea661e681098c7bdeed0ae Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 23 May 2016 12:41:11 -0400 Subject: [PATCH 280/959] Add actions overwritten by merge. --- tests/dummy/app/routes/nodes/detail.js | 96 +++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 103a25c22..093ebc93f 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -21,16 +21,78 @@ export default Ember.Route.extend({ // console.log('Will edit title from', this.modelFor(this.routeName).get('title'), ' to ', value); var node = this.modelFor(this.routeName); if (node.get('currentUserPermissions').indexOf('write') !== -1) { - console.log(title, category, description, this.routeName); if (title) {node.set('title', title);} if (category) {node.set('category', category);} if (description) {node.set('description', description);} - if (isPublic) {node.set('public', isPublic);} + if (isPublic !== null) {node.set('public', isPublic);} node.save(); } else { console.log('You do not have permissions to edit this node'); } }, + addContributor(contribId, permission, bibliographic) { + var node = this.modelFor(this.routeName); + if (contribId) { + if (node.get('currentUserPermissions').indexOf('admin') !== -1) { + var contributor = this.store.createRecord('contributor', { + id: contribId, + permission: permission, + bibliographic: bibliographic, + nodeId: node.id + }); + contributor.save(); + console.log('Contributor added.'); + } else { + console.log('You do not have permissions to add contributors'); + } + } else { + console.log('User ID must be specified.'); + } + }, + updateContributors(editedPermissions, editedBibliographic) { + var node = this.modelFor(this.routeName); + var contribMap = this.generateContributorMap(node.get('contributors')); + let user = this.modelFor('application'); + + for (var contrib in editedPermissions) { + contribMap[contrib].permission = editedPermissions[contrib]; + } + + for (var c in editedBibliographic) { + contribMap[c].bibliographic = editedBibliographic[c]; + } + + if (node.get('currentUserPermissions').indexOf('admin') !== -1) { + this.attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic); + } else { + // Non-admins can only attempt to remove themselves as contributors + if (contrib.id === user.id) { + this.attemptContributorsUpdate(contribMap, node, editedPermissions, + editedBibliographic); + } else { + console.log('Non-admins cannot update other contributors.'); + } + } + + }, + deleteContributor(contrib) { + var node = this.modelFor(this.routeName); + contrib.setProperties({ nodeId: node.id }); + let user = this.modelFor('application'); + + var contribMap = this.generateContributorMap(node.get('contributors')); + + if (node.get('currentUserPermissions').indexOf('admin') !== -1) { + this.attemptContributorRemoval(contrib, contribMap); + } else { + // Non-admins can only attempt to remove themselves as contributors + if (contrib.id === user.id) { + this.attemptContributorRemoval(contrib, contribMap); + } else { + console.log('Non-admins cannot delete other contributors.'); + } + } + }, addChildren(title, description, category) { var node = this.modelFor(this.routeName); if (node.get('currentUserPermissions').indexOf('write') !== -1) { @@ -61,6 +123,36 @@ export default Ember.Route.extend({ } }, + generateContributorMap(contributors) { + // Maps all node contributors to format {contribID: {permission: "read|write|admin", bibliographic: "true|false"}} + var contribMap = contributors.content.currentState.reduce(function(newMap, contrib) { + newMap[contrib.id] = { permission: contrib._data.permission, bibliographic: contrib._data.bibliographic }; + return newMap; + }, {}); + return contribMap; + }, + canModifyContributor(contribRemoving, contribMap) { + /** Checks to see if contributor(s) can be updated/removed. Contributor can only be updated/removed + if there is at least one other contributor with admin permissions, and at least one other bibliographic contributor **/ + var bibliographic = false; + var admin = false; + for (var contribId in contribMap) { + if (contribRemoving && contribId === contribRemoving.id) { + continue; + } else { + if (contribMap[contribId].bibliographic) { + bibliographic = true; + } + if (contribMap[contribId].permission === 'admin') { + admin = true; + } + } + } + if (bibliographic && admin) { + return true; + } + return false; + }, attemptContributorsUpdate(contribMap, node, editedPermissions, editedBibliographic) { if (this.canModifyContributor(null, contribMap)) { From 0410b98d879a95f2ff0a733f026bf59d0b028e20 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 23 May 2016 12:47:58 -0400 Subject: [PATCH 281/959] Indentation. --- .../app/templates/nodes/detail/index.hbs | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index ce3233745..de173b731 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -67,13 +67,13 @@ {{log-detail node-logs=model.logs}}

    Contributors

    - - - - - - - +
    ID Permissions Bibliographic
    + + + + + + {{#each model.contributors as |contrib|}} @@ -90,7 +90,7 @@ {{/each}} -
    ID Permissions Bibliographic
    {{contrib.id}}
    +
    @@ -110,26 +110,25 @@

    Create component

    -
    - - {{input type="text" value=title placeholder="Component's title" required=true}} - - {{input type="text" value=description placeholder="Component's description"}} -

    -

    {{radio-button name="category" value="analysis" checked=category}} Analysis

    -

    {{radio-button name="category" value="communication" checked=category}} Communication

    -

    {{radio-button name="category" value="data" checked=category}} Data

    -

    {{radio-button name="category" value="hypothesis" checked=category}} Hypothesis

    -

    {{radio-button name="category" value="instrumentation" checked=category}} Instrumentation

    -

    {{radio-button name="category" value="methods and measures" checked=category}} Methods and Measures

    -

    {{radio-button name="category" value="procedure" checked=category}} Procedure

    -

    {{radio-button name="category" value="project" checked=category}} Project

    -

    {{radio-button name="category" value="software" checked=category}} Software

    -

    {{radio-button name="category" value="other" checked=category}} Other

    -

    {{radio-button name="category" value="uncategorized" checked=category}} Uncategorized

    - -

    -
    +
    + + {{input type="text" value=title placeholder="Component's title" required=true}} + + {{input type="text" value=description placeholder="Component's description"}} +

    +

    {{radio-button name="category" value="analysis" checked=category}} Analysis

    +

    {{radio-button name="category" value="communication" checked=category}} Communication

    +

    {{radio-button name="category" value="data" checked=category}} Data

    +

    {{radio-button name="category" value="hypothesis" checked=category}} Hypothesis

    +

    {{radio-button name="category" value="instrumentation" checked=category}} Instrumentation

    +

    {{radio-button name="category" value="methods and measures" checked=category}} Methods and Measures

    +

    {{radio-button name="category" value="procedure" checked=category}} Procedure

    +

    {{radio-button name="category" value="project" checked=category}} Project

    +

    {{radio-button name="category" value="software" checked=category}} Software

    +

    {{radio-button name="category" value="other" checked=category}} Other

    +

    {{radio-button name="category" value="uncategorized" checked=category}} Uncategorized

    +

    +
    From 256ab2559e35d17a0543762cb085490491c6ea03 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Mon, 23 May 2016 12:48:28 -0400 Subject: [PATCH 282/959] Remove file (has been moved.) --- tests/dummy/app/controllers/nodes/detail.js | 24 --------------------- 1 file changed, 24 deletions(-) delete mode 100644 tests/dummy/app/controllers/nodes/detail.js diff --git a/tests/dummy/app/controllers/nodes/detail.js b/tests/dummy/app/controllers/nodes/detail.js deleted file mode 100644 index 4423f1dc6..000000000 --- a/tests/dummy/app/controllers/nodes/detail.js +++ /dev/null @@ -1,24 +0,0 @@ -import Ember from 'ember'; - -export default Ember.Controller.extend({ - editedPermissions: {}, - editedBibliographic: {}, - actions: { - expandProperties() { - this.toggleProperty('propertiesVisible'); - }, - permissionChange(permission) { - // Adds updated permissions for a certain contributor - var p = permission.split(' '); - var permissions = p[0]; - var contributorId = p[1]; - this.editedPermissions[contributorId] = permissions; - }, - bibliographicChange(target) { - // Adds updated bibliographic info for a certain contributor - var bibliographic = target.checked; - var contributorId = target.value; - this.editedBibliographic[contributorId] = bibliographic; - } - } -}); From ab34a1707f8c75c2add64994296f5f2b9aa4a491 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 24 May 2016 09:18:44 -0400 Subject: [PATCH 283/959] Encode download url before passing to MFR. --- addon/helpers/build-mfr-url.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addon/helpers/build-mfr-url.js b/addon/helpers/build-mfr-url.js index 683ae1cbf..8e286441d 100644 --- a/addon/helpers/build-mfr-url.js +++ b/addon/helpers/build-mfr-url.js @@ -4,9 +4,8 @@ import config from 'ember-get-config'; export function buildMfrUrl(params/*, hash*/) { var base = config.OSF.renderUrl; var download = params[0]; - var renderUrl = base + '?url=' + download; - // return renderUrl; - return 'http://localhost:7778/render?url=http://localhost:5000/zps63/?action=download%26direct%26mode=render&initialWidth=766&childId=mfrIframe'; + var renderUrl = base + '?url=' + encodeURIComponent(download); + return renderUrl; } export default Ember.Helper.helper(buildMfrUrl); From f32b4037182481fd1669a5a01644816c6d50b53b Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 24 May 2016 10:00:42 -0400 Subject: [PATCH 284/959] Add additional query parameters to url sent to MFR. --- addon/components/file-renderer/template.hbs | 2 +- addon/helpers/build-mfr-url.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/components/file-renderer/template.hbs b/addon/components/file-renderer/template.hbs index 844dbccd3..4f186ddac 100644 --- a/addon/components/file-renderer/template.hbs +++ b/addon/components/file-renderer/template.hbs @@ -1,2 +1,2 @@ - diff --git a/addon/helpers/build-mfr-url.js b/addon/helpers/build-mfr-url.js index 8e286441d..a90980c07 100644 --- a/addon/helpers/build-mfr-url.js +++ b/addon/helpers/build-mfr-url.js @@ -4,7 +4,7 @@ import config from 'ember-get-config'; export function buildMfrUrl(params/*, hash*/) { var base = config.OSF.renderUrl; var download = params[0]; - var renderUrl = base + '?url=' + encodeURIComponent(download); + var renderUrl = base + '?url=' + encodeURIComponent(download + '?direct&mode=render&initialWidth=766&childId=mfrIframe'); return renderUrl; } From 04f2f47f7937552afdf250cb335d160ae9eabaff Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 24 May 2016 10:05:45 -0400 Subject: [PATCH 285/959] Drop file renderer component into files/provider/file.hbs template. --- tests/dummy/app/templates/nodes/detail/files/provider/file.hbs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs index b826d7fc1..aa6eac9ec 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs @@ -45,4 +45,7 @@ {{/each}} {{/if}} + + {{#file-renderer download=model.links.download}} + {{/file-renderer}}
    From c28892f58cd54abdf1bec758631bc6ee35599ccf Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 24 May 2016 10:39:16 -0400 Subject: [PATCH 286/959] Fix bad merge of nodes/detail/index page that overwrote contributor functionality and left duplicates of the template on the page. --- .../nodes/{detail.js => detail/index.js} | 0 .../app/templates/nodes/detail/index.hbs | 61 ++++++++----------- 2 files changed, 24 insertions(+), 37 deletions(-) rename tests/dummy/app/controllers/nodes/{detail.js => detail/index.js} (100%) diff --git a/tests/dummy/app/controllers/nodes/detail.js b/tests/dummy/app/controllers/nodes/detail/index.js similarity index 100% rename from tests/dummy/app/controllers/nodes/detail.js rename to tests/dummy/app/controllers/nodes/detail/index.js diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index 36c667eb3..bd8b9a919 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -1,5 +1,5 @@ {{link-to 'Back to list' 'nodes' class="btn btn-default"}} -
    +

    Data

    {{model.title}}

    {{model.category}}

    @@ -13,54 +13,37 @@

    Edit this node

    Title: {{input value=editedTitle}} - + +

    Contributors

    - + + + {{#each model.contributors as |contrib|}} - + + + {{/each}} -
    IDAuthor? Permissions Bibliographic
    {{contrib.id}}{{contrib.bibliographic}} + + + +
    - -

    - - {{#each model.affiliatedInstitutions as |inst|}} - - {{inst.name}} - - {{/each}} -
    -

    -

    Files

    - {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}} -
    - {{log-detail node-logs=model.logs}} -
    -{{link-to 'Back to list' 'nodes' class="btn btn-default"}} -
    -

    Data

    -

    {{model.title}}

    -

    {{model.category}}

    -

    {{moment-format model.dateCreated}}

    -

    {{moment-format model.dateModified}}

    -

    - - View on OSF - -

    -
    -

    Edit this node

    - Title: {{input value=editedTitle}} - -

    Contributors

    + +
    +

    Add contributor

    {{input value=contributorID}}

    @@ -74,6 +57,7 @@


    +

    @@ -84,6 +68,9 @@ {{/each}}

    + + {{log-detail node-logs=model.logs}} +

    Files

    {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}}
    From a451a8e0f837575e01ee7853ecf747bfdd39a906 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Tue, 24 May 2016 11:09:02 -0400 Subject: [PATCH 287/959] Change incorrect test. Since component returns i-frame, there won't be text. --- tests/integration/components/file-renderer/component-test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/components/file-renderer/component-test.js b/tests/integration/components/file-renderer/component-test.js index 53a8cd78b..1ebecb87e 100644 --- a/tests/integration/components/file-renderer/component-test.js +++ b/tests/integration/components/file-renderer/component-test.js @@ -16,9 +16,8 @@ test('it renders', function(assert) { // Template block usage: this.render(hbs` {{#file-renderer}} - template block text {{/file-renderer}} `); - assert.equal(this.$().text().trim(), 'template block text'); + assert.equal(this.$().text().trim(), ''); }); From 27b28e9cba956ce3496e94e92e47f98586a1c847 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 24 May 2016 11:30:29 -0400 Subject: [PATCH 288/959] Start connecting factories for tests. Add dependencies (faker and factoryguy). This test failing- is template rendering twice?? [ci skip] [#EOSF-39] --- bower.json | 3 ++- package.json | 2 ++ tests/factories/file-version.js | 9 +++++++ .../components/file-version-test.js | 26 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/factories/file-version.js create mode 100644 tests/integration/components/file-version-test.js diff --git a/bower.json b/bower.json index d5593d67d..dab557ec7 100644 --- a/bower.json +++ b/bower.json @@ -8,7 +8,8 @@ "Faker": "~3.0.0", "pretender": "~0.10.1", "lodash": "~3.7.0", - "bootstrap-sass": "^3.3.6" + "bootstrap-sass": "^3.3.6", + "jquery-mockjax": "2.1.1" }, "devDependencies": { "bootstrap": "^3.3.6" diff --git a/package.json b/package.json index 2c4ea2e5b..9e29442f8 100644 --- a/package.json +++ b/package.json @@ -38,9 +38,11 @@ "ember-cli-uglify": "^1.2.0", "ember-component-css": "0.1.9", "ember-data": "^2.3.0", + "ember-data-factory-guy": "2.6.1", "ember-disable-prototype-extensions": "^1.0.0", "ember-disable-proxy-controllers": "^1.0.1", "ember-export-application-global": "^1.0.4", + "ember-faker": "1.1.0", "ember-i18n": "4.2.1", "ember-load-initializers": "0.5.1", "ember-resolver": "2.0.3", diff --git a/tests/factories/file-version.js b/tests/factories/file-version.js new file mode 100644 index 000000000..8afec53eb --- /dev/null +++ b/tests/factories/file-version.js @@ -0,0 +1,9 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('file-version', { + default: { + size: FactoryGuy.generate(() => faker.random.number()), + contentType: 'text/plain' + } +}); diff --git a/tests/integration/components/file-version-test.js b/tests/integration/components/file-version-test.js new file mode 100644 index 000000000..9356b0c1d --- /dev/null +++ b/tests/integration/components/file-version-test.js @@ -0,0 +1,26 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +//import FactoryGuy from 'ember-data-factory-guy'; +import FactoryGuy, {manualSetup } from 'ember-data-factory-guy'; + +moduleForComponent('file-version', 'Integration | Component | file version', { + integration: true, + + beforeEach: function() { + // Set up factory guy, per docs + manualSetup(this.container); + } +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + let version = FactoryGuy.make('file-version'); + this.render(hbs`{{file-version version=version}}`); + + assert.equal( + this.$('.file-version').children().eq(1).text(), + `Size: ${version.get('size')}`, + 'Second list element should be a label with file size'); +}); From b8a44f1d55bef867421e0f8208447a458ed7b7b3 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 24 May 2016 11:48:46 -0400 Subject: [PATCH 289/959] Working fileVersion component test w/factory [ci skip] --- .../components/file-version-test.js | 26 ------------------- .../components/file-version/component-test.js | 26 +++++++++++++------ 2 files changed, 18 insertions(+), 34 deletions(-) delete mode 100644 tests/integration/components/file-version-test.js diff --git a/tests/integration/components/file-version-test.js b/tests/integration/components/file-version-test.js deleted file mode 100644 index 9356b0c1d..000000000 --- a/tests/integration/components/file-version-test.js +++ /dev/null @@ -1,26 +0,0 @@ -import { moduleForComponent, test } from 'ember-qunit'; -import hbs from 'htmlbars-inline-precompile'; - -//import FactoryGuy from 'ember-data-factory-guy'; -import FactoryGuy, {manualSetup } from 'ember-data-factory-guy'; - -moduleForComponent('file-version', 'Integration | Component | file version', { - integration: true, - - beforeEach: function() { - // Set up factory guy, per docs - manualSetup(this.container); - } -}); - -test('it renders', function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.on('myAction', function(val) { ... }); - let version = FactoryGuy.make('file-version'); - this.render(hbs`{{file-version version=version}}`); - - assert.equal( - this.$('.file-version').children().eq(1).text(), - `Size: ${version.get('size')}`, - 'Second list element should be a label with file size'); -}); diff --git a/tests/integration/components/file-version/component-test.js b/tests/integration/components/file-version/component-test.js index 5f9b65834..4041b3e20 100644 --- a/tests/integration/components/file-version/component-test.js +++ b/tests/integration/components/file-version/component-test.js @@ -1,16 +1,26 @@ import { moduleForComponent, test } from 'ember-qunit'; import hbs from 'htmlbars-inline-precompile'; +import FactoryGuy, {manualSetup } from 'ember-data-factory-guy'; + moduleForComponent('file-version', 'Integration | Component | file version', { - integration: true + integration: true, + + beforeEach: function() { + // Set up factory guy, per docs + manualSetup(this.container); + } }); test('it renders', function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.on('myAction', function(val) { ... }); - this.set('version', {'id': '1', 'size': 125, 'contentType': 'text'}); - this.render(hbs`{{file-version version=version}}`); - - assert.equal(this.$().text().trim(), 'ID: 1\n Size: 125\n Content type: text'); - + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + let fileVersion = FactoryGuy.make('file-version'); + this.set('fileVersion', fileVersion); + this.render(hbs`{{file-version version=fileVersion}}`); + + assert.equal( + this.$('.file-version').children().eq(1).text(), + `Size: ${fileVersion.get('size')}`, + 'Second list element should be a label with file size'); }); From 919894a79689e8f474039e806daa44b780a7c4c6 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Tue, 24 May 2016 12:09:16 -0400 Subject: [PATCH 290/959] get component add to work --- addon/adapters/osf-adapter.js | 41 +++++++++++++++----------- addon/mixins/osf-model.js | 2 +- addon/models/node.js | 17 ++++++++--- addon/serializers/relationship.js | 2 +- tests/dummy/app/routes/nodes/detail.js | 8 ++--- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index fc7347a9a..dc1796287 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -13,14 +13,12 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { namespace: config.OSF.apiNamespace, buildURL(modelName, id, snapshot, requestType, query, dirtyRelationship) { // jshint ignore:line - var url; - if (dirtyRelationship) { - var links = snapshot.record.get( - `links.relationships.${Ember.String.underscore(dirtyRelationship)}.links` - ); - if (links) { - url = links.self ? links.self.href : links.related.href; - } + var url; + var links = dirtyRelationship ? snapshot.record.get( + `links.relationships.${Ember.String.underscore(dirtyRelationship)}.links` + ) : false; + if (links) { + url = links.self ? links.self.href : links.related.href; } else { url = this._super(...arguments); } @@ -34,22 +32,29 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { relationshipPayload(snapshot, dirty, store) { var relationMeta = snapshot.record[dirty].meta(); var relationType = relationMeta.type; - var Serializer = relationMeta.options.serializer || store.serializerFor( - relationType - ); - var serializer = new Serializer(); - return { - data: snapshot.record.get(dirty).map((record) => { - return serializer.serialize(new DS.Snapshot(record._internalModel)); - }) - }; + var serialized; + if (relationMeta.options.serializer) { + serialized = relationMeta.options.serializer(snapshot); + } else { + var serializer = store.serializerFor(relationType); + var toBeSent = snapshot.record.get(dirty).filter( + function(record){ + return record.id === null; + } + ); + serialized = serializer.serialize(new DS.Snapshot(toBeSent[0]._internalModel)); + // for some reason this is not hitting the node overloaded serialize method + delete serialized.data.relationships; + } + return serialized; }, updateRecord(store, type, snapshot, _, query) { var dirtyRelationships = snapshot.record.get('dirtyRelationships'); if (dirtyRelationships.length) { var dirty = dirtyRelationships.pop(); var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord', query, dirty); - return this.ajax(url, 'PATCH', { + var requestType = snapshot.record[dirty].meta().options.updateRequestType; + return this.ajax(url, requestType || 'PATCH', { data: this.relationshipPayload(snapshot, dirty, store) }); diff --git a/addon/mixins/osf-model.js b/addon/mixins/osf-model.js index a028e3242..51b3b3368 100644 --- a/addon/mixins/osf-model.js +++ b/addon/mixins/osf-model.js @@ -13,7 +13,7 @@ export default Ember.Mixin.create({ dirtyRelationships: Ember.computed('_dirtyRelationships', function() { var dirtyRelationships = this.get('_dirtyRelationships'); return Object.keys(dirtyRelationships).map((rel) => { - if (rel === 'files') { + if (rel === 'files' || rel === 'node' || rel === 'user') { return null; } if (dirtyRelationships[rel]) { diff --git a/addon/models/node.js b/addon/models/node.js index 8bd57fbb9..4d28c9488 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -3,6 +3,16 @@ import DS from 'ember-data'; import OsfModel from '../mixins/osf-model'; import RelationshipSerializer from '../serializers/relationship'; +function relationshipSerializer(relationship, type){ + return function(snapshot){ + return { + data: snapshot.record.get(relationship).map( + function(record){ return {type: type, id: record.id};} + ) + }; + } +} + export default DS.Model.extend(OsfModel, { title: DS.attr('string'), description: DS.attr('string'), @@ -26,13 +36,12 @@ export default DS.Model.extend(OsfModel, { inverse: 'children' }), children: DS.hasMany('nodes', { - inverse: 'parent' + inverse: 'parent', + updateRequestType: 'POST' }), affiliatedInstitutions: DS.hasMany('institutions', { inverse: 'nodes', - serializer: RelationshipSerializer.extend({ - type: 'institutions' - }) + serializer: relationshipSerializer('affiliatedInstitutions', 'institutions') }), comments: DS.hasMany('comments'), contributors: DS.hasMany('contributors'), diff --git a/addon/serializers/relationship.js b/addon/serializers/relationship.js index cf9d6eb68..877301300 100644 --- a/addon/serializers/relationship.js +++ b/addon/serializers/relationship.js @@ -2,7 +2,7 @@ import Serializer from 'ember-data/serializers/json-api'; export default Serializer.extend({ type: null, - serialize: function(snapshot) { + serialize: function(snapshot) { return { type: this.get('type'), id: snapshot.record.get('id') diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index 035a9a475..ba2b34bf1 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -111,16 +111,16 @@ export default Ember.Route.extend({ addChildren(title, description, category) { var node = this.modelFor(this.routeName); if (node.get('currentUserPermissions').indexOf('write') !== -1) { - var child = this.store.createRecord('children', { + var child = this.store.createRecord('node', { title: title, category: category || 'project', - description: description || null, - parentId: node.id + description: description || null }); child.one('didCreate', this, function() { this.transitionTo('nodes.detail.children'); }); - child.save(); + node.get('children').pushObject(child); + node.save(); } else { console.log('You do not have permissions to create this component'); } From d54b96a294d41cc0af3b359dc89fcec0698bfccb Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 24 May 2016 14:07:29 -0400 Subject: [PATCH 291/959] Remove unused field from comments [ci skip] --- addon/models/comment.js | 1 - tests/integration/components/file-version/component-test.js | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addon/models/comment.js b/addon/models/comment.js index b31849f43..d0ffefa41 100644 --- a/addon/models/comment.js +++ b/addon/models/comment.js @@ -3,7 +3,6 @@ import DS from 'ember-data'; import OsfModel from '../mixins/osf-model'; export default DS.Model.extend(OsfModel, { - type: DS.attr('string'), // TODO validation: maxLength content: DS.attr('string'), page: DS.attr('string'), diff --git a/tests/integration/components/file-version/component-test.js b/tests/integration/components/file-version/component-test.js index 4041b3e20..70f246e8c 100644 --- a/tests/integration/components/file-version/component-test.js +++ b/tests/integration/components/file-version/component-test.js @@ -18,9 +18,10 @@ test('it renders', function(assert) { let fileVersion = FactoryGuy.make('file-version'); this.set('fileVersion', fileVersion); this.render(hbs`{{file-version version=fileVersion}}`); - + assert.equal( this.$('.file-version').children().eq(1).text(), `Size: ${fileVersion.get('size')}`, - 'Second list element should be a label with file size'); + 'Second list element should be a label with file size' + ); }); From 36f00ac12c7e26e10c3e0d82d85897e9462df5c5 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Tue, 24 May 2016 14:14:00 -0400 Subject: [PATCH 292/959] remove relationship serializer, and mentions of it --- addon/adapters/osf-adapter.js | 1 + addon/models/node.js | 1 - addon/serializers/relationship.js | 11 ----------- app/serializers/relationship.js | 1 - tests/unit/serializers/relationship-test.js | 15 --------------- 5 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 addon/serializers/relationship.js delete mode 100644 app/serializers/relationship.js delete mode 100644 tests/unit/serializers/relationship-test.js diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index dc1796287..d39ef80a5 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -42,6 +42,7 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { return record.id === null; } ); + //under the assumption relationship saves are atomic, only one component is added at a time. serialized = serializer.serialize(new DS.Snapshot(toBeSent[0]._internalModel)); // for some reason this is not hitting the node overloaded serialize method delete serialized.data.relationships; diff --git a/addon/models/node.js b/addon/models/node.js index 4d28c9488..a22246e59 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -1,7 +1,6 @@ import DS from 'ember-data'; import OsfModel from '../mixins/osf-model'; -import RelationshipSerializer from '../serializers/relationship'; function relationshipSerializer(relationship, type){ return function(snapshot){ diff --git a/addon/serializers/relationship.js b/addon/serializers/relationship.js deleted file mode 100644 index 877301300..000000000 --- a/addon/serializers/relationship.js +++ /dev/null @@ -1,11 +0,0 @@ -import Serializer from 'ember-data/serializers/json-api'; - -export default Serializer.extend({ - type: null, - serialize: function(snapshot) { - return { - type: this.get('type'), - id: snapshot.record.get('id') - }; - } -}); diff --git a/app/serializers/relationship.js b/app/serializers/relationship.js deleted file mode 100644 index 68fb4e4b1..000000000 --- a/app/serializers/relationship.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/serializers/relationship'; diff --git a/tests/unit/serializers/relationship-test.js b/tests/unit/serializers/relationship-test.js deleted file mode 100644 index 09349ab46..000000000 --- a/tests/unit/serializers/relationship-test.js +++ /dev/null @@ -1,15 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('relationship', 'Unit | Serializer | relationship', { - // Specify the other units that are required for this test. - needs: ['serializer:relationship'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); From e660d9b7ccc30b0e2aaba4adac1fb3bf15137401 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 24 May 2016 14:20:31 -0400 Subject: [PATCH 293/959] Continue adding factories [ci skip] --- tests/factories/collection.js | 10 ++++++++++ tests/factories/comment.js | 32 ++++++++++++++++++++++++++++++++ tests/factories/user.js | 24 ++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/factories/collection.js create mode 100644 tests/factories/comment.js create mode 100644 tests/factories/user.js diff --git a/tests/factories/collection.js b/tests/factories/collection.js new file mode 100644 index 000000000..d2b53a5e6 --- /dev/null +++ b/tests/factories/collection.js @@ -0,0 +1,10 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('collection', { + default: { + title: faker.lorem.words(3), + dateCreated: faker.date.past(1), + dateModified: faker.date.recent(1) + } +}); diff --git a/tests/factories/comment.js b/tests/factories/comment.js new file mode 100644 index 000000000..98fb9ba6d --- /dev/null +++ b/tests/factories/comment.js @@ -0,0 +1,32 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('comment', { + default: { + content: faker.lorem.sentence(), + + dateCreated: FactoryGuy.generate(() => faker.date.past(1)), + dateModified: FactoryGuy.generate(() => faker.date.recent(1)), + + modified: true, + deleted: false, + + isAbuse: false, + hasChildren: false, + + canEdit: true, + }, + traits: { + // List of possible "page" values h/t Saman- must be one of these values. Mutually exclusive. + isWiki: { + page: 'wiki' + }, + isNode: { + page: 'node' + }, + isFile: { + page: 'files' + }, + // TODO: Add a hasReplies trait in the future to support replies- can we make reply page type match the specified parent type? + } +}); diff --git a/tests/factories/user.js b/tests/factories/user.js new file mode 100644 index 000000000..c030b03e0 --- /dev/null +++ b/tests/factories/user.js @@ -0,0 +1,24 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('user', { + default: { + fullName: FactoryGuy.generate(() => faker.name.findName()), + givenName: FactoryGuy.generate(() => faker.name.firstName()), + familyName: FactoryGuy.generate(() => faker.name.lastName()), + + dateRegistered: FactoryGuy.generate(() => faker.date.past(1)) + }, + traits: { + // TODO: Consider writing tests that would force pagination of relationships (!) + has_projects: { + nodes: FactoryGuy.hasMany('node', 3) + }, + has_registrations: { + registrations: FactoryGuy.hasMany('registration', 3) + }, + has_institutions: { + affiliatedInstitutions: FactoryGuy.hasMany('registration', 2) + } + } +}); From 6afedab88cacf308cd0d9dbeed8245484c017231 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Tue, 24 May 2016 14:41:35 -0400 Subject: [PATCH 294/959] remove children model, adapter and serializer --- addon/adapters/children.js | 11 ------ addon/adapters/node.js | 2 +- addon/models/children.js | 48 ------------------------- addon/serializers/children.js | 8 ----- app/adapters/children.js | 1 - app/models/children.js | 1 - app/serializers/children.js | 1 - tests/unit/adapters/children-test.js | 12 ------- tests/unit/models/children-test.js | 13 ------- tests/unit/serializers/children-test.js | 16 --------- 10 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 addon/adapters/children.js delete mode 100644 addon/models/children.js delete mode 100644 addon/serializers/children.js delete mode 100644 app/adapters/children.js delete mode 100644 app/models/children.js delete mode 100644 app/serializers/children.js delete mode 100644 tests/unit/adapters/children-test.js delete mode 100644 tests/unit/models/children-test.js delete mode 100644 tests/unit/serializers/children-test.js diff --git a/addon/adapters/children.js b/addon/adapters/children.js deleted file mode 100644 index 14e16d9d6..000000000 --- a/addon/adapters/children.js +++ /dev/null @@ -1,11 +0,0 @@ -import OsfAdapter from './osf-adapter'; - -export default OsfAdapter.extend({ - buildURL(_, __, snap) { - // Modifies URL from /children/ to nodes//children/ to match APIv2 route for creating children. - var base = this._super(...arguments); - var ar = base.split('/'); - ar.splice(4, 0, 'nodes/' + snap._attributes.parentId); - return ar.join('/'); - } -}); diff --git a/addon/adapters/node.js b/addon/adapters/node.js index 66a17c41f..1dc9ec289 100644 --- a/addon/adapters/node.js +++ b/addon/adapters/node.js @@ -1,7 +1,7 @@ import OsfAdapter from './osf-adapter'; export default OsfAdapter.extend({ - buildURL(_, __, snapshot, requestType) { + buildURL(_, __, ___, requestType) { // Embed contributors var base = this._super(...arguments); if (['createRecord', 'updateRecord', 'deleteRecord'].indexOf(requestType) === -1) { diff --git a/addon/models/children.js b/addon/models/children.js deleted file mode 100644 index c81dd0a3c..000000000 --- a/addon/models/children.js +++ /dev/null @@ -1,48 +0,0 @@ -import DS from 'ember-data'; - -import OsfModel from '../mixins/osf-model'; - -export default DS.Model.extend(OsfModel, { - title: DS.attr('string'), - description: DS.attr('string'), - category: DS.attr('string'), - parentId: DS.attr('string'), - - currentUserPermissions: DS.attr('string'), - - fork: DS.attr('boolean'), - collection: DS.attr('boolean'), - registration: DS.attr('boolean'), - public: DS.attr('boolean'), - - dateCreated: DS.attr('date'), - dateModified: DS.attr('date'), - - tags: DS.attr(), - - templateFrom: DS.attr('string'), - - parent: DS.belongsTo('node', { - inverse: 'children' - }), - children: DS.hasMany('nodes', { - inverse: 'parent' - }), - affiliatedInstitutions: DS.hasMany('institutions', { - inverse: 'nodes' - }), - comments: DS.hasMany('comments'), - contributors: DS.hasMany('contributors'), - - files: DS.hasMany('file-provider'), - //forkedFrom: DS.belongsTo('node'), - //nodeLinks: DS.hasMany('node-pointers'), - registrations: DS.hasMany('registrations', { - inverse: 'registeredFrom' - }), - - root: DS.belongsTo('node', { - inverse: null - }), - logs: DS.hasMany('logs') -}); diff --git a/addon/serializers/children.js b/addon/serializers/children.js deleted file mode 100644 index b0345b08e..000000000 --- a/addon/serializers/children.js +++ /dev/null @@ -1,8 +0,0 @@ -import OsfSerializer from './osf-serializer'; - -export default OsfSerializer.extend({ - payloadKeyFromModelName: function() { - // Overrides type 'children' with type 'nodes'. APIv2 expecting type 'nodes'. - return 'nodes'; - } -}); diff --git a/app/adapters/children.js b/app/adapters/children.js deleted file mode 100644 index cad40a625..000000000 --- a/app/adapters/children.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/adapters/children'; diff --git a/app/models/children.js b/app/models/children.js deleted file mode 100644 index 0bc501b82..000000000 --- a/app/models/children.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/models/children'; diff --git a/app/serializers/children.js b/app/serializers/children.js deleted file mode 100644 index 3ca5bec68..000000000 --- a/app/serializers/children.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/serializers/children'; diff --git a/tests/unit/adapters/children-test.js b/tests/unit/adapters/children-test.js deleted file mode 100644 index 45373afbb..000000000 --- a/tests/unit/adapters/children-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('adapter:children', 'Unit | Adapter | children', { - // Specify the other units that are required for this test. - needs: ['model:node'] -}); - -// Replace this with your real tests. -test('it exists', function(assert) { - let adapter = this.subject(); - assert.ok(adapter); -}); diff --git a/tests/unit/models/children-test.js b/tests/unit/models/children-test.js deleted file mode 100644 index f14e1e539..000000000 --- a/tests/unit/models/children-test.js +++ /dev/null @@ -1,13 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('children', 'Unit | Model | children', { - // Specify the other units that are required for this test. - needs: ['model:node', 'model:user', 'model:contributor', 'model:comment', 'model:institution', 'model:registration', 'model:file-provider', 'model:log'] - -}); - -test('it exists', function(assert) { - let model = this.subject(); - // let store = this.store(); - assert.ok(!!model); -}); diff --git a/tests/unit/serializers/children-test.js b/tests/unit/serializers/children-test.js deleted file mode 100644 index 2dae4f2d6..000000000 --- a/tests/unit/serializers/children-test.js +++ /dev/null @@ -1,16 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('children', 'Unit | Serializer | children', { - // Specify the other units that are required for this test. - needs: ['serializer:children', 'model:children', 'model:node', 'transform:links', 'transform:embed', 'model:institution', - 'model:contributor', 'model:comment', 'model:file-provider', 'model:registration', 'model:log'] -}); - -// Replace this with your real tests. -test('it serializes records', function(assert) { - let record = this.subject(); - - let serializedRecord = record.serialize(); - - assert.ok(serializedRecord); -}); From bc555a42586855135e9fc4121a0837566d426385 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Tue, 24 May 2016 14:42:01 -0400 Subject: [PATCH 295/959] Fully functional file-uploader --- addon/components/file-uploader/component.js | 81 +++++++++++++-------- addon/components/file-uploader/style.css | 8 -- addon/components/file-uploader/template.hbs | 43 ++++++----- 3 files changed, 77 insertions(+), 55 deletions(-) delete mode 100644 addon/components/file-uploader/style.css diff --git a/addon/components/file-uploader/component.js b/addon/components/file-uploader/component.js index bce42f79b..38d0d8c9a 100644 --- a/addon/components/file-uploader/component.js +++ b/addon/components/file-uploader/component.js @@ -1,53 +1,74 @@ import Ember from 'ember'; import layout from './template'; -// TODO: Upload progress? - export default Ember.Component.extend({ layout, fileManager: Ember.inject.service(), - classNames: ['file-uploader'], - classNameBindings: ['canDrop:valid-drop-zone'], - canDrop: false, - currentUploads: [], - errors: [], + classNames: ['drop-zone'], + classNameBindings: ['dropZoneReady'], + dropZoneReady: false, + currentUploads: Ember.A(), + completedUploads: Ember.A(), + errorMessage: null, dragOver(event) { - if (event.dataTransfer.files.length) { - // Stop the event bubbling, so this can accept the drag/drop - return false; - } - }, - - dragEnter(event) { - if (event.dataTransfer.files.length) { - this.set('canDrop', true); - // Stop the event bubbling, so this can accept the drag/drop + if (event.dataTransfer.types.indexOf('Files') > -1) { + this.set('dropZoneReady', true); + event.dataTransfer.dropEffect = 'move'; return false; + } else { + event.dataTransfer.dropEffect = 'none'; } }, dragLeave(event) { - this.set('canDrop', false); + this.set('dropZoneReady', false); + event.dataTransfer.dropEffect = ''; }, drop(event) { - let fm = this.get('fileManager'); - let folder = this.get('uploadFolder'); - for (let file in event.dataTransfer.files) { - this.get('currentUploads').pushObject(file); - let p = fm.uploadFile(folder, file.name, file); - p.then(() => { - this.get('currentUploads').removeObject(file); - }).catch((error) => { - this.get('errors').pushObject(error); - this.get('currentUploads').removeObject(file); - }); + event.preventDefault(); + this.set('dropZoneReady', false); + for (let i = 0; i < event.dataTransfer.files.length; i++) { + let file = event.dataTransfer.files[i]; + let p = this._fileCheck(file); + p.then(() => this._uploadFile(file)); + p.catch(() => this.set('errorMessage', + `Cannot upload directories (${file.name})`)); } }, actions: { - fileUploaded() { + uploadFile(event) { + for (let i = 0; i < event.target.files.length; i++) { + let file = event.target.files[i]; + this._uploadFile(file); + } } + }, + + _uploadFile(file) { + this.get('currentUploads').pushObject(file); + let folder = this.get('uploadFolder'); + let p = this.get('fileManager').uploadFile(folder, file.name, file); + p.then(() => { + this.get('currentUploads').removeObject(file); + this.get('completedUploads').pushObject(file); + }).catch((error) => { + this.get('currentUploads').removeObject(file); + this.set('errorMessage', error); + }); + }, + + _fileCheck(file) { + // HACK: There's not a cross-browser way to upload the contents of + // dragged-and-dropped directories, but there's also not a good way to + // tell whether a given File object is a directory. Hence, this: + return new Promise(function(resolve, reject) { + let reader = new FileReader(); + reader.onload = () => resolve(); // it's a file + reader.onerror = () => reject(); // it's a directory or something + reader.readAsText(file.slice(0, 5)); + }); } }); diff --git a/addon/components/file-uploader/style.css b/addon/components/file-uploader/style.css deleted file mode 100644 index 745f5c002..000000000 --- a/addon/components/file-uploader/style.css +++ /dev/null @@ -1,8 +0,0 @@ -.file-uploader { - height: 10em; - width: 10em; -} - -.valid-drop-zone { - border: 2px dashed blue; -} diff --git a/addon/components/file-uploader/template.hbs b/addon/components/file-uploader/template.hbs index 2959d088e..e456ac918 100644 --- a/addon/components/file-uploader/template.hbs +++ b/addon/components/file-uploader/template.hbs @@ -1,18 +1,27 @@ -Drag a file here! -{{yield}} -{{#if currentUploads}} -

    Uploads

    -
      - {{#each currentUploads as |upload|}} -
    • {{upload.name}}
    • - {{/each}} -
    -{{/if}} -{{#if errors}} -

    Errors

    -
      - {{#each errors as |error|}} -
    • {{error}}
    • - {{/each}} -
    +{{#if hasBlock}} + {{yield}} +{{else}} +

    + {{input type='file' change=(action 'uploadFile')}} +

    +

    + You can also drag and drop a file from your computer. +

    + {{#if currentUploads}} +
      + {{#each currentUploads as |upload|}} +
    • {{upload.name}} uploading...
    • + {{/each}} +
    + {{/if}} + {{#if completedUploads}} +
      + {{#each completedUploads as |upload|}} +
    • {{upload.name}} done!
    • + {{/each}} +
    + {{/if}} + {{#if errorMessage}} +
    Error: {{errorMessage}}
    + {{/if}} {{/if}} From 13f7d203dee91c9d043fe25512d03a703460ec43 Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Tue, 24 May 2016 15:02:46 -0400 Subject: [PATCH 296/959] [WIP] Add comment deletion Currently, ember removes the comment from file.comments after it is deleted, but instead of disappearing there should be a placeholder that says "Comment deleted" --- addon/components/comment-detail/component.js | 4 ++++ addon/components/comment-detail/template.hbs | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/addon/components/comment-detail/component.js b/addon/components/comment-detail/component.js index 16241dca4..c8b500521 100644 --- a/addon/components/comment-detail/component.js +++ b/addon/components/comment-detail/component.js @@ -8,6 +8,10 @@ export default Ember.Component.extend({ editedComment(comment, content) { comment.set('content', content); comment.save(); + }, + deletedComment(comment) { + comment.deleteRecord(); + comment.save(); } } }); diff --git a/addon/components/comment-detail/template.hbs b/addon/components/comment-detail/template.hbs index 9d60448d6..94b18791b 100644 --- a/addon/components/comment-detail/template.hbs +++ b/addon/components/comment-detail/template.hbs @@ -1,6 +1,12 @@
  • -
    - {{input value=model.content}} -
    + {{#if model.deleted}} +
    Comment deleted
    + {{else}} +
    + {{input value=model.content}} + +
    + {{/if}} +
  • {{yield}} From c4408c7902507c83d16bf0c0771a0399ab34692e Mon Sep 17 00:00:00 2001 From: Saman Ehsan Date: Tue, 24 May 2016 15:20:39 -0400 Subject: [PATCH 297/959] Fix indentaion errors --- addon/components/comment-detail/template.hbs | 16 ++--- tests/dummy/app/templates/file.hbs | 64 ++++++++++---------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/addon/components/comment-detail/template.hbs b/addon/components/comment-detail/template.hbs index 94b18791b..46c4b4d0d 100644 --- a/addon/components/comment-detail/template.hbs +++ b/addon/components/comment-detail/template.hbs @@ -1,12 +1,12 @@
  • - {{#if model.deleted}} -
    Comment deleted
    - {{else}} -
    - {{input value=model.content}} - + {{#if model.deleted}} +
    Comment deleted
    + {{else}} +
    + + {{input value=model.content}} +
    - {{/if}} -
    + {{/if}}
  • {{yield}} diff --git a/tests/dummy/app/templates/file.hbs b/tests/dummy/app/templates/file.hbs index 491670aef..682c17535 100644 --- a/tests/dummy/app/templates/file.hbs +++ b/tests/dummy/app/templates/file.hbs @@ -1,37 +1,35 @@
    -

    File detail

    -

    {{model.name}}

    -

    {{model.kind}}

    -

    {{model.path}}

    -

    {{model.size}}

    -

    {{model.provider}}

    -

    {{model.materializedPath}}

    -

    {{model.lastTouched}}

    -

    {{model.dateModified}}

    -

    {{model.dateCreated}}

    -

    {{model.checkout}}

    +

    File detail

    +

    {{model.name}}

    +

    {{model.kind}}

    +

    {{model.path}}

    +

    {{model.size}}

    +

    {{model.provider}}

    +

    {{model.materializedPath}}

    +

    {{model.lastTouched}}

    +

    {{model.dateModified}}

    +

    {{model.dateCreated}}

    +

    {{model.checkout}}

    -
    -

    Versions

    -
      - {{#each model.versions as |version|}} -
    • -
      {{version.id}}
      -
      {{version.size}}
      -
      {{version.contentType}}
      -
    • - {{else}} - (none) - {{/each}} -
    -
    -

    Comments

    -
      - {{#each model.comments as |comment|}} - {{comment-detail model=comment}} - {{else}} - (none) - {{/each}} -
    +

    Versions

    +
      + {{#each model.versions as |version|}} +
    • +
      {{version.id}}
      +
      {{version.size}}
      +
      {{version.contentType}}
      +
    • + {{else}} + (none) + {{/each}} +
    +

    Comments

    +
      + {{#each model.comments as |comment|}} + {{comment-detail model=comment}} + {{else}} + (none) + {{/each}} +
    From a1f2c6f699f8d2181d4fe13bb62d08d2c4febc7a Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 24 May 2016 15:54:31 -0400 Subject: [PATCH 298/959] Continue adding factories [ci skip] --- tests/factories/comment-report.js | 8 +++++++ tests/factories/contributor.js | 9 ++++++++ tests/factories/file-provider.js | 15 +++++++++++++ tests/factories/file.js | 35 +++++++++++++++++++++++++++++++ tests/factories/user.js | 6 +++--- 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/factories/comment-report.js create mode 100644 tests/factories/contributor.js create mode 100644 tests/factories/file-provider.js create mode 100644 tests/factories/file.js diff --git a/tests/factories/comment-report.js b/tests/factories/comment-report.js new file mode 100644 index 000000000..20162c444 --- /dev/null +++ b/tests/factories/comment-report.js @@ -0,0 +1,8 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('comment-report', { + default: { + category: FactoryGuy.generate(() => faker.random.arrayElement(['hate', 'spam', 'violence'])) + }, +}); diff --git a/tests/factories/contributor.js b/tests/factories/contributor.js new file mode 100644 index 000000000..e2135078a --- /dev/null +++ b/tests/factories/contributor.js @@ -0,0 +1,9 @@ +import FactoryGuy from 'ember-data-factory-guy'; + +FactoryGuy.define('contributor', { + default: { + bibliographic: true, + permission: 'admin', // Must be one of read, write, or admin + // nodeID: // TODO: Field not defined in serializer. Find out meaning and add to factory. + } +}); diff --git a/tests/factories/file-provider.js b/tests/factories/file-provider.js new file mode 100644 index 000000000..843ab58dc --- /dev/null +++ b/tests/factories/file-provider.js @@ -0,0 +1,15 @@ +import FactoryGuy from 'ember-data-factory-guy'; + +FactoryGuy.define('file-provider', { + default: { + name: 'osfstorage', + kind: 'folder', + path: '/', + provider: 'osfstorage', + }, + traits: { + hasFiles: { + files: FactoryGuy.generate(() => FactoryGuy.hasMany('file', 3)) + } + } +}); diff --git a/tests/factories/file.js b/tests/factories/file.js new file mode 100644 index 000000000..b6128e8eb --- /dev/null +++ b/tests/factories/file.js @@ -0,0 +1,35 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('file', { + default: { + name: FactoryGuy.generate(() => faker.system.fileName()), + kind: 'file', + path: '/1234567890', // Faker.system.filePath may not yet be implemented + size: FactoryGuy.generate(() => faker.random.number()), + provider: 'osfstorage', + materialized_path: "/osf_test_file.jpg", + lastTouched: null, + + dateModified: FactoryGuy.generate(() => faker.date.recent(1)), + dateCreated: FactoryGuy.generate(() => faker.date.past(1)), + + isProvider: false, + checkout: false, + }, + traits: { + // Folder specific + hasFiles: { + kind: 'folder', + files: FactoryGuy.generate(() => FactoryGuy.hasMany('file', 3)) + }, + // File specific + hasVersions: { + kind: 'file' + }, + hasComments: { + kind: 'file', + comments: FactoryGuy.generate(() => FactoryGuy.hasMany('comment', 3)) + } + } +}); diff --git a/tests/factories/user.js b/tests/factories/user.js index c030b03e0..8c13907aa 100644 --- a/tests/factories/user.js +++ b/tests/factories/user.js @@ -12,13 +12,13 @@ FactoryGuy.define('user', { traits: { // TODO: Consider writing tests that would force pagination of relationships (!) has_projects: { - nodes: FactoryGuy.hasMany('node', 3) + nodes: FactoryGuy.generate(() => FactoryGuy.hasMany('node', 3)) }, has_registrations: { - registrations: FactoryGuy.hasMany('registration', 3) + registrations: FactoryGuy.generate(() => FactoryGuy.hasMany('registration', 3)) }, has_institutions: { - affiliatedInstitutions: FactoryGuy.hasMany('registration', 2) + affiliatedInstitutions: FactoryGuy.generate(() => FactoryGuy.hasMany('institution', 2)) } } }); From b3af20df3f3ca1b87d04f2c5b3c545499b672b79 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Tue, 24 May 2016 16:12:17 -0400 Subject: [PATCH 299/959] fix style, removed unused attribute [skip ci] --- addon/adapters/osf-adapter.js | 28 ++++++++++++-------------- addon/models/institution.js | 3 --- addon/models/node.js | 18 ++++++++--------- addon/serializers/osf-serializer.js | 2 +- tests/dummy/app/routes/nodes/detail.js | 25 +++++++++++------------ 5 files changed, 35 insertions(+), 41 deletions(-) diff --git a/addon/adapters/osf-adapter.js b/addon/adapters/osf-adapter.js index d39ef80a5..27c0fe38b 100644 --- a/addon/adapters/osf-adapter.js +++ b/addon/adapters/osf-adapter.js @@ -11,9 +11,8 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { authorizer: 'authorizer:osf-token', host: config.OSF.apiUrl, namespace: config.OSF.apiNamespace, - buildURL(modelName, id, snapshot, requestType, query, dirtyRelationship) { // jshint ignore:line - var url; + var url; var links = dirtyRelationship ? snapshot.record.get( `links.relationships.${Ember.String.underscore(dirtyRelationship)}.links` ) : false; @@ -22,7 +21,7 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { } else { url = this._super(...arguments); } - // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing + // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing // slash to URLs for single documents, but DRF redirects to force a trailing slash if (url.lastIndexOf('/') !== url.length - 1) { url += '/'; @@ -34,18 +33,18 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { var relationType = relationMeta.type; var serialized; if (relationMeta.options.serializer) { - serialized = relationMeta.options.serializer(snapshot); + serialized = relationMeta.options.serializer(snapshot); } else { - var serializer = store.serializerFor(relationType); - var toBeSent = snapshot.record.get(dirty).filter( - function(record){ - return record.id === null; - } - ); - //under the assumption relationship saves are atomic, only one component is added at a time. - serialized = serializer.serialize(new DS.Snapshot(toBeSent[0]._internalModel)); - // for some reason this is not hitting the node overloaded serialize method - delete serialized.data.relationships; + var serializer = store.serializerFor(relationType); + var toBeSent = snapshot.record.get(dirty).filter( + function(record) { + return record.id === null; + } + ); + //under the assumption relationship saves are atomic, only one component is added at a time. + serialized = serializer.serialize(new DS.Snapshot(toBeSent[0]._internalModel)); + // for some reason this is not hitting the node overloaded serialize method + delete serialized.data.relationships; } return serialized; }, @@ -58,7 +57,6 @@ export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { return this.ajax(url, requestType || 'PATCH', { data: this.relationshipPayload(snapshot, dirty, store) }); - } else { return this._super(...arguments); } diff --git a/addon/models/institution.js b/addon/models/institution.js index c5ccd1614..ee7461672 100644 --- a/addon/models/institution.js +++ b/addon/models/institution.js @@ -8,9 +8,6 @@ export default DS.Model.extend(OsfModel, { logoPath: DS.attr('string'), authUrl: DS.attr('string'), - children: DS.hasMany('users', { - inverse: 'affiliatedInstitutions' - }), nodes: DS.hasMany('nodes', { inverse: 'affiliatedInstitutions' }), diff --git a/addon/models/node.js b/addon/models/node.js index a22246e59..c45554704 100644 --- a/addon/models/node.js +++ b/addon/models/node.js @@ -2,14 +2,14 @@ import DS from 'ember-data'; import OsfModel from '../mixins/osf-model'; -function relationshipSerializer(relationship, type){ - return function(snapshot){ - return { - data: snapshot.record.get(relationship).map( - function(record){ return {type: type, id: record.id};} - ) - }; - } +function relationshipSerializer(relationship, type) { + return function(snapshot) { + return { + data: snapshot.record.get(relationship).map( + function(record) { return { type: type, id: record.id }; } + ) + }; + }; } export default DS.Model.extend(OsfModel, { @@ -40,7 +40,7 @@ export default DS.Model.extend(OsfModel, { }), affiliatedInstitutions: DS.hasMany('institutions', { inverse: 'nodes', - serializer: relationshipSerializer('affiliatedInstitutions', 'institutions') + serializer: relationshipSerializer('affiliatedInstitutions', 'institutions') }), comments: DS.hasMany('comments'), contributors: DS.hasMany('contributors'), diff --git a/addon/serializers/osf-serializer.js b/addon/serializers/osf-serializer.js index 1bd9ceb54..78993107a 100644 --- a/addon/serializers/osf-serializer.js +++ b/addon/serializers/osf-serializer.js @@ -23,7 +23,7 @@ export default DS.JSONAPISerializer.extend({ resourceHash.attributes.embeds = resourceHash.embeds; } if (resourceHash.relationships && resourceHash.attributes.links) { - resourceHash.attributes.links = Ember.$.extend(resourceHash.attributes.links, {relationships: resourceHash.relationships}); + resourceHash.attributes.links = Ember.$.extend(resourceHash.attributes.links, { relationships: resourceHash.relationships }); } return resourceHash; }, diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index ba2b34bf1..ba1074a49 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -3,7 +3,6 @@ import Ember from 'ember'; // TODO: refactor permissions strings when https://github.com/CenterForOpenScience/ember-osf/pull/23/files#diff-7fd0bf247bef3c257e0fcfd7e544a338R5 is merged export default Ember.Route.extend({ - model(params) { return this.store.findRecord('node', params.node_id); }, @@ -30,21 +29,21 @@ export default Ember.Route.extend({ console.log('You do not have permissions to edit this node'); } }, - affiliateNode(instId){ - var self = this; + affiliateNode(instId) { + var _this = this; self.store.findRecord('institution', instId).then( - function(inst){ - var node = self.modelFor(self.routeName); - node.get('affiliatedInstitutions').pushObject(inst); - node.save(); - } + function(inst) { + var node = _this.modelFor(self.routeName); + node.get('affiliatedInstitutions').pushObject(inst); + node.save(); + } ); }, - deaffiliateNode(inst) { - var node = this.modelFor(this.routeName); - node.get('affiliatedInstitutions').removeObject(inst); - node.save(); - }, + deaffiliateNode(inst) { + var node = this.modelFor(this.routeName); + node.get('affiliatedInstitutions').removeObject(inst); + node.save(); + }, addContributor(contribId, permission, bibliographic) { var node = this.modelFor(this.routeName); if (contribId) { From 830a9d7133ccdc5752ca5780f464117aa8a46230 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Tue, 24 May 2016 17:40:47 -0400 Subject: [PATCH 300/959] Pivot to more reusable file-chooser component [skip ci] --- .../component.js | 57 ++++++++++++------- addon/components/file-chooser/template.hbs | 21 +++++++ addon/components/file-uploader/template.hbs | 27 --------- app/components/file-chooser/component.js | 1 + app/components/file-uploader/component.js | 1 - .../app/components/file-actions/component.js | 6 +- .../app/components/file-actions/template.hbs | 11 +++- tests/dummy/app/router.js | 1 + tests/dummy/app/routes/prereg.js | 6 ++ tests/dummy/app/templates/prereg.hbs | 8 +++ .../component-test.js | 8 +-- 11 files changed, 89 insertions(+), 58 deletions(-) rename addon/components/{file-uploader => file-chooser}/component.js (55%) create mode 100644 addon/components/file-chooser/template.hbs delete mode 100644 addon/components/file-uploader/template.hbs create mode 100644 app/components/file-chooser/component.js delete mode 100644 app/components/file-uploader/component.js create mode 100644 tests/dummy/app/routes/prereg.js create mode 100644 tests/dummy/app/templates/prereg.hbs rename tests/integration/components/{file-uploader => file-chooser}/component-test.js (74%) diff --git a/addon/components/file-uploader/component.js b/addon/components/file-chooser/component.js similarity index 55% rename from addon/components/file-uploader/component.js rename to addon/components/file-chooser/component.js index 38d0d8c9a..34175cf2d 100644 --- a/addon/components/file-uploader/component.js +++ b/addon/components/file-chooser/component.js @@ -1,15 +1,35 @@ import Ember from 'ember'; import layout from './template'; +/* + * file-chooser component + * + * This component lets the user choose files from their computer, either through + * a file browser or by drag-and-drop. + * + * Exposed to parent context (bindable attributes) + * - `onChoose`: action called each time a file is added, with the new File + * object as the only argument + * - `files`: mutable list of chosen File objects + * + * Exposed to child context (block) + * - `files`: mutable list of chosen File objects, yielded to block + * - `errorMessage`: most recent error message, yielded to block + * - `onFileInputChange`: action to handle files chosen through a file input + * e.g. `{{input type='file' change=(action 'onFileInputChange')}}` + * + * Styling + * - This component's element has the `drop-zone` class + * - While the user is holding dragged files over this component, it + * has the `drop-zone-ready` class + */ + export default Ember.Component.extend({ layout, - fileManager: Ember.inject.service(), classNames: ['drop-zone'], classNameBindings: ['dropZoneReady'], dropZoneReady: false, - currentUploads: Ember.A(), - completedUploads: Ember.A(), - errorMessage: null, + files: Ember.A(), dragOver(event) { if (event.dataTransfer.types.indexOf('Files') > -1) { @@ -32,36 +52,31 @@ export default Ember.Component.extend({ for (let i = 0; i < event.dataTransfer.files.length; i++) { let file = event.dataTransfer.files[i]; let p = this._fileCheck(file); - p.then(() => this._uploadFile(file)); + p.then(() => this.actions.onChooseFile(file)); p.catch(() => this.set('errorMessage', `Cannot upload directories (${file.name})`)); } }, actions: { - uploadFile(event) { + onFileInputChange(event) { for (let i = 0; i < event.target.files.length; i++) { let file = event.target.files[i]; - this._uploadFile(file); + this.actions.onChooseFile(file); } - } - }, + }, - _uploadFile(file) { - this.get('currentUploads').pushObject(file); - let folder = this.get('uploadFolder'); - let p = this.get('fileManager').uploadFile(folder, file.name, file); - p.then(() => { - this.get('currentUploads').removeObject(file); - this.get('completedUploads').pushObject(file); - }).catch((error) => { - this.get('currentUploads').removeObject(file); - this.set('errorMessage', error); - }); + onChooseFile(file) { + this.get('files').pushObject(file); + let onChoose = this.get('onChoose'); + if (onChoose) { + onChoose(file); + } + } }, _fileCheck(file) { - // HACK: There's not a cross-browser way to upload the contents of + // HACK: There's not a cross-browser way to see the contents of // dragged-and-dropped directories, but there's also not a good way to // tell whether a given File object is a directory. Hence, this: return new Promise(function(resolve, reject) { diff --git a/addon/components/file-chooser/template.hbs b/addon/components/file-chooser/template.hbs new file mode 100644 index 000000000..fcc03a5d2 --- /dev/null +++ b/addon/components/file-chooser/template.hbs @@ -0,0 +1,21 @@ +{{#if hasBlock}} + {{yield files errorMessage}} +{{else}} +

    + {{input type='file' change=(action 'onFileInputChange')}} +

    +

    + You can also drag and drop a file from your computer. +

    + {{#if errorMessage}} +
    Error: {{errorMessage}}
    + {{/if}} + {{#if files}} +

    Chosen files

    +
      + {{#each files as |file|}} +
    • file.name
    • + {{/each}} +
    + {{/if}} +{{/if}} diff --git a/addon/components/file-uploader/template.hbs b/addon/components/file-uploader/template.hbs deleted file mode 100644 index e456ac918..000000000 --- a/addon/components/file-uploader/template.hbs +++ /dev/null @@ -1,27 +0,0 @@ -{{#if hasBlock}} - {{yield}} -{{else}} -

    - {{input type='file' change=(action 'uploadFile')}} -

    -

    - You can also drag and drop a file from your computer. -

    - {{#if currentUploads}} -
      - {{#each currentUploads as |upload|}} -
    • {{upload.name}} uploading...
    • - {{/each}} -
    - {{/if}} - {{#if completedUploads}} -
      - {{#each completedUploads as |upload|}} -
    • {{upload.name}} done!
    • - {{/each}} -
    - {{/if}} - {{#if errorMessage}} -
    Error: {{errorMessage}}
    - {{/if}} -{{/if}} diff --git a/app/components/file-chooser/component.js b/app/components/file-chooser/component.js new file mode 100644 index 000000000..d574a2612 --- /dev/null +++ b/app/components/file-chooser/component.js @@ -0,0 +1 @@ +export { default } from 'ember-osf/components/file-chooser/component'; \ No newline at end of file diff --git a/app/components/file-uploader/component.js b/app/components/file-uploader/component.js deleted file mode 100644 index 0a7c77c79..000000000 --- a/app/components/file-uploader/component.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/components/file-uploader/component'; \ No newline at end of file diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index 17570e707..88075eb85 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -33,15 +33,17 @@ export default Ember.Component.extend({ } }, - uploadFile(evt) { + uploadFiles(files) { + let fm = this.get('fileManager'); + /* TODO let newFile = evt.target.files[0]; let folder = this.get('file'); if (newFile) { - let fm = this.get('fileManager'); fm.uploadFile(folder, newFile.name, newFile).then(() => { this.get('onChange')(); }); } + */ }, rename(newName) { diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index 98ad802c7..e283f5461 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -65,10 +65,15 @@ - Upload file: + Upload files: - - {{file-uploader uploadFolder=file}} + + {{file-chooser files=filesToUpload}} + + + {{else}} diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 90348562a..79dd8ccde 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -50,6 +50,7 @@ Router.map(function() { path: '/:collection_id' }); }); + this.route('prereg'); }); export default Router; diff --git a/tests/dummy/app/routes/prereg.js b/tests/dummy/app/routes/prereg.js new file mode 100644 index 000000000..a7b0b1923 --- /dev/null +++ b/tests/dummy/app/routes/prereg.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; + +// TODO: really simple use case for file-chooser +export default Ember.Route.extend({ + +}); diff --git a/tests/dummy/app/templates/prereg.hbs b/tests/dummy/app/templates/prereg.hbs new file mode 100644 index 000000000..e96179269 --- /dev/null +++ b/tests/dummy/app/templates/prereg.hbs @@ -0,0 +1,8 @@ +
    +

    + +

    +

    + {{file-chooser files=files}} +

    +
    diff --git a/tests/integration/components/file-uploader/component-test.js b/tests/integration/components/file-chooser/component-test.js similarity index 74% rename from tests/integration/components/file-uploader/component-test.js rename to tests/integration/components/file-chooser/component-test.js index 8f3da738f..5d0fc4b12 100644 --- a/tests/integration/components/file-uploader/component-test.js +++ b/tests/integration/components/file-chooser/component-test.js @@ -1,7 +1,7 @@ import { moduleForComponent, test } from 'ember-qunit'; import hbs from 'htmlbars-inline-precompile'; -moduleForComponent('file-uploader', 'Integration | Component | file uploader', { +moduleForComponent('file-chooser', 'Integration | Component | file chooser', { integration: true }); @@ -9,15 +9,15 @@ test('it renders', function(assert) { // Set any properties with this.set('myProperty', 'value'); // Handle any actions with this.on('myAction', function(val) { ... }); - this.render(hbs`{{file-uploader}}`); + this.render(hbs`{{file-chooser}}`); assert.equal(this.$().text().trim(), ''); // Template block usage: this.render(hbs` - {{#file-uploader}} + {{#file-chooser}} template block text - {{/file-uploader}} + {{/file-chooser}} `); assert.equal(this.$().text().trim(), 'template block text'); From 963517e20f3221ba3e508a589360be4768ee3230 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 24 May 2016 22:58:39 -0400 Subject: [PATCH 301/959] Continue adding factories and improve some randomizers [ci skip] --- tests/factories/contributor.js | 5 ++-- tests/factories/file-version.js | 2 +- tests/factories/file.js | 12 ++++++-- tests/factories/institution.js | 20 +++++++++++++ tests/factories/log.js | 31 ++++++++++++++++++++ tests/factories/node.js | 51 +++++++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 tests/factories/institution.js create mode 100644 tests/factories/log.js create mode 100644 tests/factories/node.js diff --git a/tests/factories/contributor.js b/tests/factories/contributor.js index e2135078a..bf728ecdd 100644 --- a/tests/factories/contributor.js +++ b/tests/factories/contributor.js @@ -1,9 +1,10 @@ import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; FactoryGuy.define('contributor', { default: { - bibliographic: true, - permission: 'admin', // Must be one of read, write, or admin + bibliographic: FactoryGuy.generate(() => faker.random.boolean()), + permission: FactoryGuy.generate(() => faker.random.arrayElement(['read', 'write', 'admin'])) // nodeID: // TODO: Field not defined in serializer. Find out meaning and add to factory. } }); diff --git a/tests/factories/file-version.js b/tests/factories/file-version.js index 8afec53eb..bd2ca8f21 100644 --- a/tests/factories/file-version.js +++ b/tests/factories/file-version.js @@ -4,6 +4,6 @@ import faker from 'faker'; FactoryGuy.define('file-version', { default: { size: FactoryGuy.generate(() => faker.random.number()), - contentType: 'text/plain' + contentType: FactoryGuy.generate(() => faker.system.mimeType()), } }); diff --git a/tests/factories/file.js b/tests/factories/file.js index b6128e8eb..da5875e68 100644 --- a/tests/factories/file.js +++ b/tests/factories/file.js @@ -8,7 +8,9 @@ FactoryGuy.define('file', { path: '/1234567890', // Faker.system.filePath may not yet be implemented size: FactoryGuy.generate(() => faker.random.number()), provider: 'osfstorage', - materialized_path: "/osf_test_file.jpg", + materializedPath: FactoryGuy.generate(() => { + return '/' + faker.system.fileName(); + }), lastTouched: null, dateModified: FactoryGuy.generate(() => faker.date.recent(1)), @@ -19,13 +21,17 @@ FactoryGuy.define('file', { }, traits: { // Folder specific - hasFiles: { + isFolder: { kind: 'folder', + materializedPath: FactoryGuy.generate(() => { + return '/' + faker.lorem.word(); + }), files: FactoryGuy.generate(() => FactoryGuy.hasMany('file', 3)) }, // File specific hasVersions: { - kind: 'file' + kind: 'file', + versions: FactoryGuy.generate(() => FactoryGuy.hasMany('file-version', 3)) }, hasComments: { kind: 'file', diff --git a/tests/factories/institution.js b/tests/factories/institution.js new file mode 100644 index 000000000..a5aeb0e7f --- /dev/null +++ b/tests/factories/institution.js @@ -0,0 +1,20 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('institution', { + default: { + name: FactoryGuy.generate(() => faker.lorem.words(3)), + description: FactoryGuy.generate(() => faker.lorem.description(3)), + logoPath: '/img.jpg', + authUrl: FactoryGuy.generate(() => faker.internet.url()) + }, + traits: { + // TODO: Add children relations, if that field turns out to be needed after all (henrique) + hasNodes: { + nodes: FactoryGuy.generate(() => FactoryGuy.hasMany('node', 3)) + }, + hasRegistrations: { + registrations: FactoryGuy.generate(() => FactoryGuy.hasMany('registration', 3)) + } + } +}); diff --git a/tests/factories/log.js b/tests/factories/log.js new file mode 100644 index 000000000..ef8fd147a --- /dev/null +++ b/tests/factories/log.js @@ -0,0 +1,31 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('log', { + default: { + date: FactoryGuy.generate(() => faker.date.past(1)), + // Horked directly from Nodelog.actions + action: FactoryGuy.generate(() => faker.random.arrayElement( + [ + 'checked_in', 'checked_out', 'file_tag_removed', 'file_tag_added', + 'created_from', 'project_created', 'project_registered', 'project_deleted', + 'node_created', 'node_forked', 'node_removed', 'pointer_created', + 'pointer_forked', 'pointer_removed', 'wiki_updated', 'wiki_deleted', + 'wiki_renamed', 'made_wiki_public', 'made_wiki_private', 'contributor_added', + 'contributor_removed', 'contributors_reordered', 'permissions_updated', 'made_private', + 'made_public', 'tag_added', 'tag_removed', 'edit_title', + 'edit_description', 'updated_fields', 'addon_file_moved', 'addon_file_copied', + 'folder_created', 'file_added', 'file_updated', 'file_removed', + 'file_restored', 'addon_added', 'addon_removed', 'comment_added', + 'comment_removed', 'comment_updated', 'made_contributor_visible', 'made_contributor_invisible', + 'external_ids_added', 'embargo_approved', 'embargo_cancelled', 'embargo_completed', + 'embargo_initiated', 'retraction_approved', 'retraction_cancelled', 'retraction_initiated', + 'registration_cancelled', 'registration_initiated', 'registration_approved', 'prereg_registration_initiated', + 'citation_added', 'citation_edited', 'citation_removed', 'primary_institution_changed', + 'primary_institution_removed' + ] + )), + params: {}, // Correct info from this field will depend on the log type + // TODO: Figure out node vs originalnode vs linkedNode vs templateNode, and add sample traits with correct values + } +}); diff --git a/tests/factories/node.js b/tests/factories/node.js new file mode 100644 index 000000000..7b13d9944 --- /dev/null +++ b/tests/factories/node.js @@ -0,0 +1,51 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('node', { + default: { + title: FactoryGuy.generate(() => faker.lorem.words(4)), + description: FactoryGuy.generate(() => faker.lorem.paragraphs(2, '\n')), + + category: FactoryGuy.generate(() => faker.random.arrayElement( + [ + 'analysis', 'communication', 'data', 'hypothesis', + 'instrumentation', 'methods and measures', 'procedure', 'project', + 'software', 'other', '' + ] + )), + + currentUserPermissions: FactoryGuy.generate(() => faker.random.arrayElement(['read', 'write', 'admin'])), + + fork: false, + collection: false, + registration: false, + public: FactoryGuy.generate(() => faker.random.boolean()), + + dateCreated: FactoryGuy.generate(() => faker.date.past(1)), + dateModified: FactoryGuy.generate(() => faker.date.recent(1)), + }, + traits: { + hasChildren: { // Has one layer of child projects + children: FactoryGuy.generate(() => FactoryGuy.hasMany('node', 3)) + }, + hasInstitution: { + affiliatedInstitutions: FactoryGuy.generate(() => FactoryGuy.hasMany('institution', 1)) + }, + hasComments: { + comments: FactoryGuy.generate(() => FactoryGuy.hasMany('comment', 3)) + }, + hasContributors: { + contributors: FactoryGuy.generate(() => FactoryGuy.hasMany('contributor', 3)) + }, + hasFiles: { + // TOOD: Verify usage of trait in factory; it's not well documented + files: FactoryGuy.generate(() => FactoryGuy.hasMany('file-provider', 3, 'hasFiles')) + }, + hasRegistrations: { + registrations: FactoryGuy.generate(() => FactoryGuy.hasMany('registration', 1)) + }, + hasLogs: { + logs: FactoryGuy.generate(() => FactoryGuy.hasMany('log', 5)) + } + } +}); From a693db5382644b4884f1cafb145fd4565d241afe Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 24 May 2016 23:09:08 -0400 Subject: [PATCH 302/959] Add registration factory [ci skip] --- tests/factories/registration.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/factories/registration.js diff --git a/tests/factories/registration.js b/tests/factories/registration.js new file mode 100644 index 000000000..301596536 --- /dev/null +++ b/tests/factories/registration.js @@ -0,0 +1,29 @@ +import FactoryGuy from 'ember-data-factory-guy'; +import faker from 'faker'; + +FactoryGuy.define('registration', { + default: { + dateRegistered: FactoryGuy.generate(() => faker.date.past(1)), + pendingRegistrationApproval: false, + + embargoEndDate: FactoryGuy.generate(() => faker.date.future(1)), + pendingEmbargoApproval: false, + + withdrawn: false, + pendingWithdrawal: false, + + // TODO: Implement with sample data for faker, possibly traits for different reg types + registrationSupplement: null, + registeredMeta: null, + + registeredFrom: FactoryGuy.generate(() => FactoryGuy.belongsTo('node')), + registeredBy: FactoryGuy.generate(() => FactoryGuy.belongsTo('user')), + + contributors: FactoryGuy.generate(() => FactoryGuy.hasMany('contributor', 3)), + }, + traits: { + hasComments: { + comments: FactoryGuy.generate(() => FactoryGuy.hasMany('comment', 3)) + } + } +}); From 90c3bf780b162dcd75446e07cbfa1a067a8a2e1d Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 24 May 2016 23:24:22 -0400 Subject: [PATCH 303/959] Appease linters [ci skip] --- tests/factories/collection.js | 10 +++++----- tests/factories/comment.js | 2 +- tests/factories/file-version.js | 8 ++++---- tests/factories/file.js | 10 +++------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/factories/collection.js b/tests/factories/collection.js index d2b53a5e6..dd75221a1 100644 --- a/tests/factories/collection.js +++ b/tests/factories/collection.js @@ -2,9 +2,9 @@ import FactoryGuy from 'ember-data-factory-guy'; import faker from 'faker'; FactoryGuy.define('collection', { - default: { - title: faker.lorem.words(3), - dateCreated: faker.date.past(1), - dateModified: faker.date.recent(1) - } + default: { + title: faker.lorem.words(3), + dateCreated: faker.date.past(1), + dateModified: faker.date.recent(1) + } }); diff --git a/tests/factories/comment.js b/tests/factories/comment.js index 98fb9ba6d..010d47fba 100644 --- a/tests/factories/comment.js +++ b/tests/factories/comment.js @@ -13,7 +13,7 @@ FactoryGuy.define('comment', { isAbuse: false, hasChildren: false, - + canEdit: true, }, traits: { diff --git a/tests/factories/file-version.js b/tests/factories/file-version.js index bd2ca8f21..429ef6ff9 100644 --- a/tests/factories/file-version.js +++ b/tests/factories/file-version.js @@ -2,8 +2,8 @@ import FactoryGuy from 'ember-data-factory-guy'; import faker from 'faker'; FactoryGuy.define('file-version', { - default: { - size: FactoryGuy.generate(() => faker.random.number()), - contentType: FactoryGuy.generate(() => faker.system.mimeType()), - } + default: { + size: FactoryGuy.generate(() => faker.random.number()), + contentType: 'text/plain', // faker.system may not come with older versions of lib + } }); diff --git a/tests/factories/file.js b/tests/factories/file.js index da5875e68..02fa8bfd1 100644 --- a/tests/factories/file.js +++ b/tests/factories/file.js @@ -3,14 +3,12 @@ import faker from 'faker'; FactoryGuy.define('file', { default: { - name: FactoryGuy.generate(() => faker.system.fileName()), + name: FactoryGuy.generate(() => faker.lorem.word() + '.txt'), kind: 'file', path: '/1234567890', // Faker.system.filePath may not yet be implemented size: FactoryGuy.generate(() => faker.random.number()), provider: 'osfstorage', - materializedPath: FactoryGuy.generate(() => { - return '/' + faker.system.fileName(); - }), + materializedPath: FactoryGuy.generate(() => '/' + faker.lorem.word() + '.png'), lastTouched: null, dateModified: FactoryGuy.generate(() => faker.date.recent(1)), @@ -23,9 +21,7 @@ FactoryGuy.define('file', { // Folder specific isFolder: { kind: 'folder', - materializedPath: FactoryGuy.generate(() => { - return '/' + faker.lorem.word(); - }), + materializedPath: FactoryGuy.generate(() => '/' + faker.lorem.word()), files: FactoryGuy.generate(() => FactoryGuy.hasMany('file', 3)) }, // File specific From 181307ff270d6319b60f127708a9f3c40271a662 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Tue, 24 May 2016 23:37:42 -0400 Subject: [PATCH 304/959] Simplify sequence gen --> inline functions for faker fields --- tests/factories/comment-report.js | 2 +- tests/factories/comment.js | 6 +++--- tests/factories/contributor.js | 4 ++-- tests/factories/file-provider.js | 2 +- tests/factories/file-version.js | 2 +- tests/factories/file.js | 18 ++++++++--------- tests/factories/institution.js | 10 +++++----- tests/factories/log.js | 8 ++++---- tests/factories/node.js | 32 +++++++++++++++---------------- tests/factories/registration.js | 12 ++++++------ tests/factories/user.js | 14 +++++++------- 11 files changed, 55 insertions(+), 55 deletions(-) diff --git a/tests/factories/comment-report.js b/tests/factories/comment-report.js index 20162c444..8b0de5beb 100644 --- a/tests/factories/comment-report.js +++ b/tests/factories/comment-report.js @@ -3,6 +3,6 @@ import faker from 'faker'; FactoryGuy.define('comment-report', { default: { - category: FactoryGuy.generate(() => faker.random.arrayElement(['hate', 'spam', 'violence'])) + category: () => faker.random.arrayElement(['hate', 'spam', 'violence']) }, }); diff --git a/tests/factories/comment.js b/tests/factories/comment.js index 010d47fba..18463f080 100644 --- a/tests/factories/comment.js +++ b/tests/factories/comment.js @@ -3,10 +3,10 @@ import faker from 'faker'; FactoryGuy.define('comment', { default: { - content: faker.lorem.sentence(), + content: () => faker.lorem.sentence(), - dateCreated: FactoryGuy.generate(() => faker.date.past(1)), - dateModified: FactoryGuy.generate(() => faker.date.recent(1)), + dateCreated: () => faker.date.past(1), + dateModified: () => faker.date.recent(1), modified: true, deleted: false, diff --git a/tests/factories/contributor.js b/tests/factories/contributor.js index bf728ecdd..0cac37005 100644 --- a/tests/factories/contributor.js +++ b/tests/factories/contributor.js @@ -3,8 +3,8 @@ import faker from 'faker'; FactoryGuy.define('contributor', { default: { - bibliographic: FactoryGuy.generate(() => faker.random.boolean()), - permission: FactoryGuy.generate(() => faker.random.arrayElement(['read', 'write', 'admin'])) + bibliographic: () => faker.random.boolean(), + permission: () => faker.random.arrayElement(['read', 'write', 'admin']) // nodeID: // TODO: Field not defined in serializer. Find out meaning and add to factory. } }); diff --git a/tests/factories/file-provider.js b/tests/factories/file-provider.js index 843ab58dc..d0989b591 100644 --- a/tests/factories/file-provider.js +++ b/tests/factories/file-provider.js @@ -9,7 +9,7 @@ FactoryGuy.define('file-provider', { }, traits: { hasFiles: { - files: FactoryGuy.generate(() => FactoryGuy.hasMany('file', 3)) + files: () => FactoryGuy.hasMany('file', 3) } } }); diff --git a/tests/factories/file-version.js b/tests/factories/file-version.js index 429ef6ff9..8e368caa0 100644 --- a/tests/factories/file-version.js +++ b/tests/factories/file-version.js @@ -3,7 +3,7 @@ import faker from 'faker'; FactoryGuy.define('file-version', { default: { - size: FactoryGuy.generate(() => faker.random.number()), + size: () => faker.random.number(), contentType: 'text/plain', // faker.system may not come with older versions of lib } }); diff --git a/tests/factories/file.js b/tests/factories/file.js index 02fa8bfd1..bd9b0147a 100644 --- a/tests/factories/file.js +++ b/tests/factories/file.js @@ -3,16 +3,16 @@ import faker from 'faker'; FactoryGuy.define('file', { default: { - name: FactoryGuy.generate(() => faker.lorem.word() + '.txt'), + name: () => faker.lorem.word() + '.txt', kind: 'file', path: '/1234567890', // Faker.system.filePath may not yet be implemented - size: FactoryGuy.generate(() => faker.random.number()), + size: () => faker.random.number(), provider: 'osfstorage', - materializedPath: FactoryGuy.generate(() => '/' + faker.lorem.word() + '.png'), + materializedPath: () => '/' + faker.lorem.word() + '.png', lastTouched: null, - dateModified: FactoryGuy.generate(() => faker.date.recent(1)), - dateCreated: FactoryGuy.generate(() => faker.date.past(1)), + dateModified: () => faker.date.recent(1), + dateCreated: () => faker.date.past(1), isProvider: false, checkout: false, @@ -21,17 +21,17 @@ FactoryGuy.define('file', { // Folder specific isFolder: { kind: 'folder', - materializedPath: FactoryGuy.generate(() => '/' + faker.lorem.word()), - files: FactoryGuy.generate(() => FactoryGuy.hasMany('file', 3)) + materializedPath: () => '/' + faker.lorem.word(), + files: () => FactoryGuy.hasMany('file', 3) }, // File specific hasVersions: { kind: 'file', - versions: FactoryGuy.generate(() => FactoryGuy.hasMany('file-version', 3)) + versions: () => FactoryGuy.hasMany('file-version', 3) }, hasComments: { kind: 'file', - comments: FactoryGuy.generate(() => FactoryGuy.hasMany('comment', 3)) + comments: () => FactoryGuy.hasMany('comment', 3) } } }); diff --git a/tests/factories/institution.js b/tests/factories/institution.js index a5aeb0e7f..ef750773f 100644 --- a/tests/factories/institution.js +++ b/tests/factories/institution.js @@ -3,18 +3,18 @@ import faker from 'faker'; FactoryGuy.define('institution', { default: { - name: FactoryGuy.generate(() => faker.lorem.words(3)), - description: FactoryGuy.generate(() => faker.lorem.description(3)), + name: () => faker.lorem.words(3), + description: () => faker.lorem.description(3), logoPath: '/img.jpg', - authUrl: FactoryGuy.generate(() => faker.internet.url()) + authUrl: () => faker.internet.url() }, traits: { // TODO: Add children relations, if that field turns out to be needed after all (henrique) hasNodes: { - nodes: FactoryGuy.generate(() => FactoryGuy.hasMany('node', 3)) + nodes: () => FactoryGuy.hasMany('node', 3) }, hasRegistrations: { - registrations: FactoryGuy.generate(() => FactoryGuy.hasMany('registration', 3)) + registrations: () => FactoryGuy.hasMany('registration', 3) } } }); diff --git a/tests/factories/log.js b/tests/factories/log.js index ef8fd147a..b9a49c9f0 100644 --- a/tests/factories/log.js +++ b/tests/factories/log.js @@ -3,9 +3,9 @@ import faker from 'faker'; FactoryGuy.define('log', { default: { - date: FactoryGuy.generate(() => faker.date.past(1)), - // Horked directly from Nodelog.actions - action: FactoryGuy.generate(() => faker.random.arrayElement( + date: () => faker.date.past(1), + // Extracted from Nodelog.actions as of May 24, 2016 + action: () => faker.random.arrayElement( [ 'checked_in', 'checked_out', 'file_tag_removed', 'file_tag_added', 'created_from', 'project_created', 'project_registered', 'project_deleted', @@ -24,7 +24,7 @@ FactoryGuy.define('log', { 'citation_added', 'citation_edited', 'citation_removed', 'primary_institution_changed', 'primary_institution_removed' ] - )), + ), params: {}, // Correct info from this field will depend on the log type // TODO: Figure out node vs originalnode vs linkedNode vs templateNode, and add sample traits with correct values } diff --git a/tests/factories/node.js b/tests/factories/node.js index 7b13d9944..377301836 100644 --- a/tests/factories/node.js +++ b/tests/factories/node.js @@ -3,49 +3,49 @@ import faker from 'faker'; FactoryGuy.define('node', { default: { - title: FactoryGuy.generate(() => faker.lorem.words(4)), - description: FactoryGuy.generate(() => faker.lorem.paragraphs(2, '\n')), - - category: FactoryGuy.generate(() => faker.random.arrayElement( + title: () => faker.lorem.words(4), + description: () => faker.lorem.paragraphs(2, '\n'), + // Extracted from Node model CATEGORY_MAP as of May 24, 2016 + category: () => faker.random.arrayElement( [ 'analysis', 'communication', 'data', 'hypothesis', 'instrumentation', 'methods and measures', 'procedure', 'project', 'software', 'other', '' ] - )), + ), - currentUserPermissions: FactoryGuy.generate(() => faker.random.arrayElement(['read', 'write', 'admin'])), + currentUserPermissions: () => faker.random.arrayElement(['read', 'write', 'admin']), fork: false, collection: false, registration: false, - public: FactoryGuy.generate(() => faker.random.boolean()), + public: () => faker.random.boolean(), - dateCreated: FactoryGuy.generate(() => faker.date.past(1)), - dateModified: FactoryGuy.generate(() => faker.date.recent(1)), + dateCreated: () => faker.date.past(1), + dateModified: () => faker.date.recent(1), }, traits: { hasChildren: { // Has one layer of child projects - children: FactoryGuy.generate(() => FactoryGuy.hasMany('node', 3)) + children: () => FactoryGuy.hasMany('node', 3) }, hasInstitution: { - affiliatedInstitutions: FactoryGuy.generate(() => FactoryGuy.hasMany('institution', 1)) + affiliatedInstitutions: () => FactoryGuy.hasMany('institution', 1) }, hasComments: { - comments: FactoryGuy.generate(() => FactoryGuy.hasMany('comment', 3)) + comments: () => FactoryGuy.hasMany('comment', 3) }, hasContributors: { - contributors: FactoryGuy.generate(() => FactoryGuy.hasMany('contributor', 3)) + contributors: () => FactoryGuy.hasMany('contributor', 3) }, hasFiles: { // TOOD: Verify usage of trait in factory; it's not well documented - files: FactoryGuy.generate(() => FactoryGuy.hasMany('file-provider', 3, 'hasFiles')) + files: () => FactoryGuy.hasMany('file-provider', 3, 'hasFiles') }, hasRegistrations: { - registrations: FactoryGuy.generate(() => FactoryGuy.hasMany('registration', 1)) + registrations: () => FactoryGuy.hasMany('registration', 1) }, hasLogs: { - logs: FactoryGuy.generate(() => FactoryGuy.hasMany('log', 5)) + logs: () => FactoryGuy.hasMany('log', 5) } } }); diff --git a/tests/factories/registration.js b/tests/factories/registration.js index 301596536..861167430 100644 --- a/tests/factories/registration.js +++ b/tests/factories/registration.js @@ -3,10 +3,10 @@ import faker from 'faker'; FactoryGuy.define('registration', { default: { - dateRegistered: FactoryGuy.generate(() => faker.date.past(1)), + dateRegistered: () => faker.date.past(1), pendingRegistrationApproval: false, - embargoEndDate: FactoryGuy.generate(() => faker.date.future(1)), + embargoEndDate: () => faker.date.future(1), pendingEmbargoApproval: false, withdrawn: false, @@ -16,14 +16,14 @@ FactoryGuy.define('registration', { registrationSupplement: null, registeredMeta: null, - registeredFrom: FactoryGuy.generate(() => FactoryGuy.belongsTo('node')), - registeredBy: FactoryGuy.generate(() => FactoryGuy.belongsTo('user')), + registeredFrom: () => FactoryGuy.belongsTo('node'), + registeredBy: () => FactoryGuy.belongsTo('user'), - contributors: FactoryGuy.generate(() => FactoryGuy.hasMany('contributor', 3)), + contributors: () => FactoryGuy.hasMany('contributor', 3), }, traits: { hasComments: { - comments: FactoryGuy.generate(() => FactoryGuy.hasMany('comment', 3)) + comments: () => FactoryGuy.hasMany('comment', 3) } } }); diff --git a/tests/factories/user.js b/tests/factories/user.js index 8c13907aa..4f5a61201 100644 --- a/tests/factories/user.js +++ b/tests/factories/user.js @@ -3,22 +3,22 @@ import faker from 'faker'; FactoryGuy.define('user', { default: { - fullName: FactoryGuy.generate(() => faker.name.findName()), - givenName: FactoryGuy.generate(() => faker.name.firstName()), - familyName: FactoryGuy.generate(() => faker.name.lastName()), + fullName: () => faker.name.findName(), + givenName: () => faker.name.firstName(), + familyName: () => faker.name.lastName(), - dateRegistered: FactoryGuy.generate(() => faker.date.past(1)) + dateRegistered: () => faker.date.past(1) }, traits: { // TODO: Consider writing tests that would force pagination of relationships (!) has_projects: { - nodes: FactoryGuy.generate(() => FactoryGuy.hasMany('node', 3)) + nodes: () => FactoryGuy.hasMany('node', 3) }, has_registrations: { - registrations: FactoryGuy.generate(() => FactoryGuy.hasMany('registration', 3)) + registrations: () => FactoryGuy.hasMany('registration', 3) }, has_institutions: { - affiliatedInstitutions: FactoryGuy.generate(() => FactoryGuy.hasMany('institution', 2)) + affiliatedInstitutions: () => FactoryGuy.hasMany('institution', 2) } } }); From 59b8d0811978d58c5da41c92d186aef191d7f79a Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 25 May 2016 09:56:19 -0400 Subject: [PATCH 305/959] fix the user-institution relationship misnaming --- addon/models/institution.js | 3 +++ addon/models/user.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addon/models/institution.js b/addon/models/institution.js index ee7461672..0f6130f7b 100644 --- a/addon/models/institution.js +++ b/addon/models/institution.js @@ -8,6 +8,9 @@ export default DS.Model.extend(OsfModel, { logoPath: DS.attr('string'), authUrl: DS.attr('string'), + users: DS.hasMany('users', { + inverse: 'affiliatedInstitutions' + }), nodes: DS.hasMany('nodes', { inverse: 'affiliatedInstitutions' }), diff --git a/addon/models/user.js b/addon/models/user.js index 134e590e3..6e7ec9fe3 100644 --- a/addon/models/user.js +++ b/addon/models/user.js @@ -14,6 +14,6 @@ export default DS.Model.extend(OsfModel, { registrations: DS.hasMany('registrations'), affiliatedInstitutions: DS.hasMany('institutions', { - inverse: 'children' + inverse: 'users' }) }); From b0406c5e65d45a8d2b3c9ad47ad7ae25be864678 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 25 May 2016 10:06:06 -0400 Subject: [PATCH 306/959] Instead of using a template helper to build the MFR url, make the url a computed value of the file renderer component. --- addon/components/file-renderer/component.js | 10 +++++++++- addon/helpers/build-mfr-url.js | 11 ----------- app/helpers/build-mfr-url.js | 1 - tests/unit/helpers/build-mfr-url-test.js | 10 ---------- 4 files changed, 9 insertions(+), 23 deletions(-) delete mode 100644 addon/helpers/build-mfr-url.js delete mode 100644 app/helpers/build-mfr-url.js delete mode 100644 tests/unit/helpers/build-mfr-url-test.js diff --git a/addon/components/file-renderer/component.js b/addon/components/file-renderer/component.js index 44bf16cc0..ff6be19f4 100644 --- a/addon/components/file-renderer/component.js +++ b/addon/components/file-renderer/component.js @@ -1,6 +1,14 @@ import Ember from 'ember'; import layout from './template'; +import config from 'ember-get-config'; export default Ember.Component.extend({ - layout + layout, + download: null, + mfrUrl: Ember.computed('download', function() { + var base = config.OSF.renderUrl; + var download = this.get('download'); + var renderUrl = base + '?url=' + encodeURIComponent(download + '?direct&mode=render&initialWidth=766&childId=mfrIframe'); + return renderUrl; + }) }); diff --git a/addon/helpers/build-mfr-url.js b/addon/helpers/build-mfr-url.js deleted file mode 100644 index a90980c07..000000000 --- a/addon/helpers/build-mfr-url.js +++ /dev/null @@ -1,11 +0,0 @@ -import Ember from 'ember'; -import config from 'ember-get-config'; - -export function buildMfrUrl(params/*, hash*/) { - var base = config.OSF.renderUrl; - var download = params[0]; - var renderUrl = base + '?url=' + encodeURIComponent(download + '?direct&mode=render&initialWidth=766&childId=mfrIframe'); - return renderUrl; -} - -export default Ember.Helper.helper(buildMfrUrl); diff --git a/app/helpers/build-mfr-url.js b/app/helpers/build-mfr-url.js deleted file mode 100644 index de1b939a3..000000000 --- a/app/helpers/build-mfr-url.js +++ /dev/null @@ -1 +0,0 @@ -export { default, buildMfrUrl } from 'ember-osf/helpers/build-mfr-url'; diff --git a/tests/unit/helpers/build-mfr-url-test.js b/tests/unit/helpers/build-mfr-url-test.js deleted file mode 100644 index f14eff57d..000000000 --- a/tests/unit/helpers/build-mfr-url-test.js +++ /dev/null @@ -1,10 +0,0 @@ -import { buildMfrUrl } from 'dummy/helpers/build-mfr-url'; -import { module, test } from 'qunit'; - -module('Unit | Helper | build mfr url'); - -// Replace this with your real tests. -test('it works', function(assert) { - let result = buildMfrUrl([42]); - assert.ok(result); -}); From 04ff97089f3a593e3bf7f799a25ab11c802cf386 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 25 May 2016 10:06:32 -0400 Subject: [PATCH 307/959] Allow users to pass in width and height of file renderer. --- addon/components/file-renderer/template.hbs | 2 +- tests/dummy/app/templates/nodes/detail/files/provider/file.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/components/file-renderer/template.hbs b/addon/components/file-renderer/template.hbs index 4f186ddac..883075fd4 100644 --- a/addon/components/file-renderer/template.hbs +++ b/addon/components/file-renderer/template.hbs @@ -1,2 +1,2 @@ - diff --git a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs index aa6eac9ec..3cb76bac7 100644 --- a/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs +++ b/tests/dummy/app/templates/nodes/detail/files/provider/file.hbs @@ -46,6 +46,6 @@ {{/if}} - {{#file-renderer download=model.links.download}} + {{#file-renderer download=model.links.download width="1000" height="1000"}} {{/file-renderer}}
    From fd2a40750e97b3b62a3c427d739e4578b330d9e8 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 25 May 2016 10:18:11 -0400 Subject: [PATCH 308/959] Remove childId from renderUrl. --- addon/components/file-renderer/component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/components/file-renderer/component.js b/addon/components/file-renderer/component.js index ff6be19f4..5418dc4d8 100644 --- a/addon/components/file-renderer/component.js +++ b/addon/components/file-renderer/component.js @@ -8,7 +8,7 @@ export default Ember.Component.extend({ mfrUrl: Ember.computed('download', function() { var base = config.OSF.renderUrl; var download = this.get('download'); - var renderUrl = base + '?url=' + encodeURIComponent(download + '?direct&mode=render&initialWidth=766&childId=mfrIframe'); + var renderUrl = base + '?url=' + encodeURIComponent(download + '?direct&mode=render&initialWidth=766'); return renderUrl; }) }); From bfef2cf443eec4f166bbbc6db3741aca89bc58e2 Mon Sep 17 00:00:00 2001 From: Henrique Moco Date: Wed, 25 May 2016 10:20:47 -0400 Subject: [PATCH 309/959] Clean up linting --- tests/dummy/app/routes/nodes/detail.js | 4 +-- .../app/templates/nodes/detail/index.hbs | 32 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/dummy/app/routes/nodes/detail.js b/tests/dummy/app/routes/nodes/detail.js index ba1074a49..14dcc2c69 100644 --- a/tests/dummy/app/routes/nodes/detail.js +++ b/tests/dummy/app/routes/nodes/detail.js @@ -31,9 +31,9 @@ export default Ember.Route.extend({ }, affiliateNode(instId) { var _this = this; - self.store.findRecord('institution', instId).then( + _this.store.findRecord('institution', instId).then( function(inst) { - var node = _this.modelFor(self.routeName); + var node = _this.modelFor(_this.routeName); node.get('affiliatedInstitutions').pushObject(inst); node.save(); } diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index c0794d2de..e80f69e65 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -53,23 +53,23 @@ {{/if}}

    Affiliated Institutions

    -

    - - {{#each model.affiliatedInstitutions as |inst|}} - - - +

    +

    - {{inst.name}} - - -
    + {{#each model.affiliatedInstitutions as |inst|}} + + + - {{/each}} -
    + {{inst.name}} + + +
    -

    Add Institution

    - Institution Id {{input value=instId}} - -

    + {{/each}} + +

    Add Institution

    + Institution Id {{input value=instId}} + +

    Files

    {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}}
    From fe69aebdc0d091b95ec80d05b81717bc7171f474 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Wed, 25 May 2016 10:49:39 -0400 Subject: [PATCH 310/959] Fix typo and try less es6 in tests --- .github/CONTRIBUTING.md | 4 ++-- tests/integration/components/file-version/component-test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 8230e85c4..0f34b9af2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -9,7 +9,7 @@ Code style checking is part of the Travis build, and PRs that do not meet the co Please review and adhere to the naming conventions defined [here](http://ember-cli.com/user-guide/#naming-conventions) -### Accessability +### Accessibility The [ember-a11y](https://www.npmjs.com/package/ember-a11y) addon is a dependency of this addon, and helps facilitate compliance with the guidelines laid out by the [A11y Project](http://a11yproject.com/). This requires one simple change: wherever you would normally use the `{{outlet}}` helper, instead use `{{focusing-outlet}}`. See the project page for more details. @@ -51,7 +51,7 @@ _Do test_: Integration tests allow us to see how components behave while actually running in a browser enviornment. [TODO](https://openscience.atlassian.net/browse/EOSF-28) -#### Accessability checks +#### Accessibility checks We will use the [ember-a11y-testing](https://github.com/trentmwillis/ember-a11y-testing) addon to run a11y checks on all components. diff --git a/tests/integration/components/file-version/component-test.js b/tests/integration/components/file-version/component-test.js index 70f246e8c..b165da5bd 100644 --- a/tests/integration/components/file-version/component-test.js +++ b/tests/integration/components/file-version/component-test.js @@ -15,7 +15,7 @@ moduleForComponent('file-version', 'Integration | Component | file version', { test('it renders', function(assert) { // Set any properties with this.set('myProperty', 'value'); // Handle any actions with this.on('myAction', function(val) { ... }); - let fileVersion = FactoryGuy.make('file-version'); + var fileVersion = FactoryGuy.make('file-version'); this.set('fileVersion', fileVersion); this.render(hbs`{{file-version version=fileVersion}}`); From f9639831d2d01cfad745f9355f76bd6bd305e932 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 25 May 2016 10:53:54 -0400 Subject: [PATCH 311/959] Add height and width defaults for mfr renderer --- addon/components/file-renderer/component.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addon/components/file-renderer/component.js b/addon/components/file-renderer/component.js index 5418dc4d8..23cc87e1b 100644 --- a/addon/components/file-renderer/component.js +++ b/addon/components/file-renderer/component.js @@ -5,6 +5,8 @@ import config from 'ember-get-config'; export default Ember.Component.extend({ layout, download: null, + width: '100%', + height: '100%', mfrUrl: Ember.computed('download', function() { var base = config.OSF.renderUrl; var download = this.get('download'); From 3326db119829147b3d77ae59b7ccf4a5b19a6b57 Mon Sep 17 00:00:00 2001 From: Dawn Pattison Date: Wed, 25 May 2016 12:04:12 -0400 Subject: [PATCH 312/959] Add tests for the file-renderer component. --- .../file-renderer/component-test.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/integration/components/file-renderer/component-test.js b/tests/integration/components/file-renderer/component-test.js index 1ebecb87e..d231a7fc3 100644 --- a/tests/integration/components/file-renderer/component-test.js +++ b/tests/integration/components/file-renderer/component-test.js @@ -1,5 +1,6 @@ import { moduleForComponent, test } from 'ember-qunit'; import hbs from 'htmlbars-inline-precompile'; +import config from 'ember-get-config'; moduleForComponent('file-renderer', 'Integration | Component | file renderer', { integration: true @@ -21,3 +22,30 @@ test('it renders', function(assert) { assert.equal(this.$().text().trim(), ''); }); + +test('file rendering defaults', function(assert) { + + this.render(hbs` + {{#file-renderer}} + {{/file-renderer}} + `); + + assert.equal(this.$('iframe').attr('height'), '100%'); + assert.equal(this.$('iframe').attr('width'), '100%'); + assert.equal(this.$('iframe').attr('src'), config.OSF.renderUrl + "?url=" + encodeURIComponent(null + '?direct&mode=render&initialWidth=766')); +}); + +test('specify file rendering parameters', function(assert) { + this.set('download', 'http://cos.io/'); + this.set('height', '500'); + this.set('width', '500'); + + this.render(hbs` + {{#file-renderer download=download height=height width=width}} + {{/file-renderer}} + `); + + assert.equal(this.$('iframe').attr('height'), '500'); + assert.equal(this.$('iframe').attr('width'), '500'); + assert.equal(this.$('iframe').attr('src'), config.OSF.renderUrl + "?url=" + encodeURIComponent('http://cos.io/' + '?direct&mode=render&initialWidth=766')); +}); From b31ddd3f54a6d437698526311a2abe78e3f8d7ed Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Wed, 25 May 2016 12:52:10 -0400 Subject: [PATCH 313/959] Add `phantomjs-prebuilt` as a dependency due to travis issue. Future TODO: If this works, consider use of cachine for faster build process. --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9e29442f8..745a136d0 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,11 @@ "ember-cli-uglify": "^1.2.0", "ember-component-css": "0.1.9", "ember-data": "^2.3.0", - "ember-data-factory-guy": "2.6.1", + "ember-data-factory-guy": "^2.6.1", "ember-disable-prototype-extensions": "^1.0.0", "ember-disable-proxy-controllers": "^1.0.1", "ember-export-application-global": "^1.0.4", - "ember-faker": "1.1.0", + "ember-faker": "^1.1.0", "ember-i18n": "4.2.1", "ember-load-initializers": "0.5.1", "ember-resolver": "2.0.3", @@ -51,7 +51,8 @@ "jscs": "^3.0.3", "loader": "2.1.0", "loader.js": "4.0.3", - "moment": "^2.13.0" + "moment": "^2.13.0", + "phantomjs-prebuilt": "^2.1.7" }, "keywords": [ "ember-addon" From 6178c7552f9126506b6b9b1181c6d087b107a701 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 25 May 2016 13:17:03 -0400 Subject: [PATCH 314/959] Make file-chooser's list available to parent [skip ci] --- addon/components/file-chooser/component.js | 42 ++++++++++++++-------- addon/components/file-chooser/template.hbs | 4 +-- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/addon/components/file-chooser/component.js b/addon/components/file-chooser/component.js index 34175cf2d..304bbc2b3 100644 --- a/addon/components/file-chooser/component.js +++ b/addon/components/file-chooser/component.js @@ -4,24 +4,30 @@ import layout from './template'; /* * file-chooser component * - * This component lets the user choose files from their computer, either through - * a file browser or by drag-and-drop. + * This component lets the user choose a list of files from their computer, by + * drag-and-drop, a file browser, or whatever method the developer wants. * * Exposed to parent context (bindable attributes) - * - `onChoose`: action called each time a file is added, with the new File + * - `onChoose`: function called each time a file is added, with the new File * object as the only argument * - `files`: mutable list of chosen File objects * - * Exposed to child context (block) - * - `files`: mutable list of chosen File objects, yielded to block - * - `errorMessage`: most recent error message, yielded to block + * Exposed to block context + * - `this`: the component object itself, so the block can invoke actions + * + * Actions * - `onFileInputChange`: action to handle files chosen through a file input - * e.g. `{{input type='file' change=(action 'onFileInputChange')}}` + * - `onChooseFile`: if you use a different way * * Styling * - This component's element has the `drop-zone` class * - While the user is holding dragged files over this component, it * has the `drop-zone-ready` class + * + * {{#file-chooser files=fileList as |component|}} + * {{input type='file' + * change=(action 'onFileInputChange' target=component)}} + * {{/file-chooser}} */ export default Ember.Component.extend({ @@ -29,7 +35,6 @@ export default Ember.Component.extend({ classNames: ['drop-zone'], classNameBindings: ['dropZoneReady'], dropZoneReady: false, - files: Ember.A(), dragOver(event) { if (event.dataTransfer.types.indexOf('Files') > -1) { @@ -49,10 +54,11 @@ export default Ember.Component.extend({ drop(event) { event.preventDefault(); this.set('dropZoneReady', false); + let callback = this.get('onChoose'); for (let i = 0; i < event.dataTransfer.files.length; i++) { let file = event.dataTransfer.files[i]; let p = this._fileCheck(file); - p.then(() => this.actions.onChooseFile(file)); + p.then(() => this.send('onChooseFile', file, callback)); p.catch(() => this.set('errorMessage', `Cannot upload directories (${file.name})`)); } @@ -62,15 +68,21 @@ export default Ember.Component.extend({ onFileInputChange(event) { for (let i = 0; i < event.target.files.length; i++) { let file = event.target.files[i]; - this.actions.onChooseFile(file); + let callback = this.get('onChoose'); + this.send('onChooseFile', file, callback); } }, - onChooseFile(file) { - this.get('files').pushObject(file); - let onChoose = this.get('onChoose'); - if (onChoose) { - onChoose(file); + onChooseFile(file, callback) { + let files = this.get('files'); + if (typeof files === 'undefined') { + this.set('files', Ember.A()); + files = this.get('files'); + } + files.pushObject(file); + + if (callback) { + callback(file); } } }, diff --git a/addon/components/file-chooser/template.hbs b/addon/components/file-chooser/template.hbs index fcc03a5d2..e7672aa78 100644 --- a/addon/components/file-chooser/template.hbs +++ b/addon/components/file-chooser/template.hbs @@ -1,5 +1,5 @@ {{#if hasBlock}} - {{yield files errorMessage}} + {{yield this}} {{else}}

    {{input type='file' change=(action 'onFileInputChange')}} @@ -14,7 +14,7 @@

    Chosen files

      {{#each files as |file|}} -
    • file.name
    • +
    • {{file.name}}
    • {{/each}}
    {{/if}} From e9aaf7131c1c554abede624f070e1d690767265e Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 25 May 2016 13:19:04 -0400 Subject: [PATCH 315/959] Use file-chooser for uploading files [skip ci] --- tests/dummy/app/components/file-actions/component.js | 8 +++----- tests/dummy/app/components/file-actions/template.hbs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index 88075eb85..e82666f4c 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -35,15 +35,13 @@ export default Ember.Component.extend({ uploadFiles(files) { let fm = this.get('fileManager'); - /* TODO - let newFile = evt.target.files[0]; let folder = this.get('file'); - if (newFile) { - fm.uploadFile(folder, newFile.name, newFile).then(() => { + while(files && files.length) { + let file = files.pop(); + fm.uploadFile(folder, file.name, file).then(() => { this.get('onChange')(); }); } - */ }, rename(newName) { diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index e283f5461..321d0a091 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -72,7 +72,7 @@ From 76c840c13513cf67e88a81b6a4ed9d9a8c592d45 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 25 May 2016 13:20:41 -0400 Subject: [PATCH 316/959] Prereg page to demonstrate file-chooser Doesn't do anything, it's just a demo of using file-chooser as a block component. [skip ci] --- tests/dummy/app/routes/prereg.js | 20 ++++++++++++++++++-- tests/dummy/app/templates/prereg.hbs | 24 +++++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/tests/dummy/app/routes/prereg.js b/tests/dummy/app/routes/prereg.js index a7b0b1923..08b65ca99 100644 --- a/tests/dummy/app/routes/prereg.js +++ b/tests/dummy/app/routes/prereg.js @@ -1,6 +1,22 @@ import Ember from 'ember'; +import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -// TODO: really simple use case for file-chooser -export default Ember.Route.extend({ +export default Ember.Route.extend(AuthenticatedRouteMixin, { + fileManager: Ember.inject.service(), + actions: { + preregister(name, files) { + let store = this.get('store'); + let fileNames = files.mapBy('name').join(', '); + + // TODO: This page is just a file-chooser demo at this point + alert(`Files: ${fileNames}`); + + // store.createRecord('node', { title: name, ... }) + + // for (let file of files) { + // this.get('fileManager').uploadFile(...) + // } + } + } }); diff --git a/tests/dummy/app/templates/prereg.hbs b/tests/dummy/app/templates/prereg.hbs index e96179269..c147421c4 100644 --- a/tests/dummy/app/templates/prereg.hbs +++ b/tests/dummy/app/templates/prereg.hbs @@ -3,6 +3,28 @@

    - {{file-chooser files=files}} + {{#file-chooser files=files as |component|}} +

    + Drag your preregistration files here! +

    +

    + Or choose them, if you're not into HTML5: + {{input type='file' + change=(action 'onFileInputChange' target=component)}} +

    + {{#if files}} +

    Selected files

    +
      + {{#each files as |file|}} +
    • {{file.name}}
    • + {{/each}} +
    + {{/if}} + {{/file-chooser}} +

    +

    +

    From c6f5c1863819b93694de5a0e73d4c20882f74978 Mon Sep 17 00:00:00 2001 From: Sam Chrisinger Date: Wed, 25 May 2016 14:13:04 -0400 Subject: [PATCH 317/959] Revert "WIP adding mirage factories/models" This reverts commit 05d2260710da21fa1bc29fca73793066c5eae92c. --- app/mirage-factories/contributor.js | 1 - app/mirage-factories/institution.js | 1 - app/mirage-factories/log.js | 1 - app/mirage-factories/node.js | 1 - app/mirage-factories/registration.js | 1 - app/mirage-factories/user.js | 1 - app/mirage-models/contributor.js | 1 - app/mirage-models/institutions.js | 1 - app/mirage-models/logs.js | 1 - app/mirage-models/node.js | 1 - app/mirage-models/registration.js | 1 - app/mirage-models/user.js | 1 - tests/dummy/mirage/config.js | 48 ------------------- tests/dummy/mirage/factories/contributor.js | 17 ------- tests/dummy/mirage/factories/institution.js | 5 -- tests/dummy/mirage/factories/log.js | 5 -- tests/dummy/mirage/factories/node.js | 42 ---------------- tests/dummy/mirage/factories/registration.js | 45 ----------------- tests/dummy/mirage/factories/user.js | 14 ------ tests/dummy/mirage/models/contributor.js | 8 ---- tests/dummy/mirage/models/institutions.js | 16 ------- tests/dummy/mirage/models/logs.js | 12 ----- tests/dummy/mirage/models/node.js | 26 ---------- tests/dummy/mirage/models/registration.js | 13 ----- tests/dummy/mirage/models/user.js | 12 ----- tests/dummy/mirage/scenarios/default.js | 11 ----- tests/dummy/mirage/serializers/application.js | 4 -- tests/dummy/mirage/util.js | 7 --- 28 files changed, 297 deletions(-) delete mode 100644 app/mirage-factories/contributor.js delete mode 100644 app/mirage-factories/institution.js delete mode 100644 app/mirage-factories/log.js delete mode 100644 app/mirage-factories/node.js delete mode 100644 app/mirage-factories/registration.js delete mode 100644 app/mirage-factories/user.js delete mode 100644 app/mirage-models/contributor.js delete mode 100644 app/mirage-models/institutions.js delete mode 100644 app/mirage-models/logs.js delete mode 100644 app/mirage-models/node.js delete mode 100644 app/mirage-models/registration.js delete mode 100644 app/mirage-models/user.js delete mode 100644 tests/dummy/mirage/config.js delete mode 100644 tests/dummy/mirage/factories/contributor.js delete mode 100644 tests/dummy/mirage/factories/institution.js delete mode 100644 tests/dummy/mirage/factories/log.js delete mode 100644 tests/dummy/mirage/factories/node.js delete mode 100644 tests/dummy/mirage/factories/registration.js delete mode 100644 tests/dummy/mirage/factories/user.js delete mode 100644 tests/dummy/mirage/models/contributor.js delete mode 100644 tests/dummy/mirage/models/institutions.js delete mode 100644 tests/dummy/mirage/models/logs.js delete mode 100644 tests/dummy/mirage/models/node.js delete mode 100644 tests/dummy/mirage/models/registration.js delete mode 100644 tests/dummy/mirage/models/user.js delete mode 100644 tests/dummy/mirage/scenarios/default.js delete mode 100644 tests/dummy/mirage/serializers/application.js delete mode 100644 tests/dummy/mirage/util.js diff --git a/app/mirage-factories/contributor.js b/app/mirage-factories/contributor.js deleted file mode 100644 index 3249bd653..000000000 --- a/app/mirage-factories/contributor.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-factories/contributor'; diff --git a/app/mirage-factories/institution.js b/app/mirage-factories/institution.js deleted file mode 100644 index 0c5770ae7..000000000 --- a/app/mirage-factories/institution.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-factories/institution'; diff --git a/app/mirage-factories/log.js b/app/mirage-factories/log.js deleted file mode 100644 index 52ca0ef07..000000000 --- a/app/mirage-factories/log.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-factories/log'; diff --git a/app/mirage-factories/node.js b/app/mirage-factories/node.js deleted file mode 100644 index 10a7cd899..000000000 --- a/app/mirage-factories/node.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-factories/node'; diff --git a/app/mirage-factories/registration.js b/app/mirage-factories/registration.js deleted file mode 100644 index df76bfa89..000000000 --- a/app/mirage-factories/registration.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-factories/registration'; diff --git a/app/mirage-factories/user.js b/app/mirage-factories/user.js deleted file mode 100644 index 02d727f56..000000000 --- a/app/mirage-factories/user.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-factories/user'; diff --git a/app/mirage-models/contributor.js b/app/mirage-models/contributor.js deleted file mode 100644 index bd70b6526..000000000 --- a/app/mirage-models/contributor.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-models/contributor'; diff --git a/app/mirage-models/institutions.js b/app/mirage-models/institutions.js deleted file mode 100644 index ebb7882dd..000000000 --- a/app/mirage-models/institutions.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-models/institutions'; diff --git a/app/mirage-models/logs.js b/app/mirage-models/logs.js deleted file mode 100644 index 04c1295a8..000000000 --- a/app/mirage-models/logs.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-models/logs'; diff --git a/app/mirage-models/node.js b/app/mirage-models/node.js deleted file mode 100644 index 02a453a5e..000000000 --- a/app/mirage-models/node.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-models/node'; diff --git a/app/mirage-models/registration.js b/app/mirage-models/registration.js deleted file mode 100644 index e1af39942..000000000 --- a/app/mirage-models/registration.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-models/registration'; diff --git a/app/mirage-models/user.js b/app/mirage-models/user.js deleted file mode 100644 index da6828fac..000000000 --- a/app/mirage-models/user.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-osf/mirage-models/user'; diff --git a/tests/dummy/mirage/config.js b/tests/dummy/mirage/config.js deleted file mode 100644 index 799a0c4b5..000000000 --- a/tests/dummy/mirage/config.js +++ /dev/null @@ -1,48 +0,0 @@ -export default function() { - - // These comments are here to help you get started. Feel free to delete them. - - /* - Config (with defaults). - - Note: these only affect routes defined *after* them! - */ - - this.urlPrefix = 'http://localhost:8000'; - this.namespace = 'v2'; - // this.timing = 400; // delay for each request, automatically set to 0 during testing - - this.get('/users/', (schema) => schema.user.all()); - this.get('/users/:id/', (schema, request) => schema.user.find(request.params.id)); - this.get('/users/:id/nodes', (schema, request) => schema.user.find(request.params.id).nodes.all()); - this.get('/users/:id/relationships/institutions/', (schema, request) => schema.user.find(request.params.id).institutions.all()); - this.get('/users/:id/registrations/', (schema, request) => schema.user.find(request.params.id).registrations.all()); - - this.get('/nodes/', (schema) => schema.node.all()); - this.get('/nodes/:id/', (schema, request) => schema.node.find(request.params.id)); - this.get('/nodes/:id/contributors/', (schema, request) => schema.node.find(request.params.id).contributors.all()); - this.get('/nodes/:id/logs/', (schema, request) => schema.node.find(request.params.id).logs.all()); - - this.get('/registrations/', (schema) => schema.registration.all()); - this.get('/registrations/:id/', (schema, request) => schema.registration.find(request.params.id)); - this.get('/registrations/:id/contributors/', (schema, request) => schema.registration.find(request.params.id).contributors.all()); - this.get('/registrations/:id/logs/', (schema, request) => schema.registration.find(request.params.id).logs.all()); - - this.get('/logs/', (schema) => schema.log.all()); - this.get('/logs/:id/', (schema, request) => schema.log.find(request.params.id)); - this.get('/logs/:id/contributors/', (schema, request) => schema.log.find(request.params.id).contributors.all()); - - this.get('/institutions/', (schema) => schema.institution.all()); - this.get('/institutions/:id/nodes/', (schema, request) => schema.institution.find(request.params.id).nodes.all()); - this.get('/institutions/:id/registrations/', (schema, request) => schema.institution.find(request.params.id).registrations.all()); - this.get('/institutions/:id/users/', (schema, request) => schema.institution.find(request.params.id).users.all()); - - /* - Shorthand cheatsheet: - this.get('/posts'); - this.post('/posts'); - this.get('/posts/:id'); - this.put('/posts/:id'); // or this.patch - this.del('/posts/:id'); - */ -} diff --git a/tests/dummy/mirage/factories/contributor.js b/tests/dummy/mirage/factories/contributor.js deleted file mode 100644 index 0ec1f5d9f..000000000 --- a/tests/dummy/mirage/factories/contributor.js +++ /dev/null @@ -1,17 +0,0 @@ -import { - Factory, - faker -} from 'ember-cli-mirage'; - -import { - PERMISSIONS -} from 'ember-osf/const/permissions'; - -import { - pickOne -} from '../util'; - -export default Factory.extend({ - bibliographic: faker.random.boolean, - permission: pickOne(PERMISSIONS) -}); diff --git a/tests/dummy/mirage/factories/institution.js b/tests/dummy/mirage/factories/institution.js deleted file mode 100644 index 588c646b3..000000000 --- a/tests/dummy/mirage/factories/institution.js +++ /dev/null @@ -1,5 +0,0 @@ -import { - Factory -} from 'ember-cli-mirage'; - -export default Factory.extend({}); diff --git a/tests/dummy/mirage/factories/log.js b/tests/dummy/mirage/factories/log.js deleted file mode 100644 index 588c646b3..000000000 --- a/tests/dummy/mirage/factories/log.js +++ /dev/null @@ -1,5 +0,0 @@ -import { - Factory -} from 'ember-cli-mirage'; - -export default Factory.extend({}); diff --git a/tests/dummy/mirage/factories/node.js b/tests/dummy/mirage/factories/node.js deleted file mode 100644 index 00c7dea7f..000000000 --- a/tests/dummy/mirage/factories/node.js +++ /dev/null @@ -1,42 +0,0 @@ -import { - Factory, - faker -} from 'ember-cli-mirage'; - -import NodeModel from 'ember-osf/models/node'; -var CATEGORIES = Object.keys(NodeModel.CATEGORY_MAP); - -import { - pickOne -} from '../util'; - -import { - PERMISSIONS -} from 'ember-osf/const/permissions'; - -export default Factory.extend({ - title: function() { - return `${faker.hacker.adjective()} ${faker.hacker.noun()} ${faker.hacker.verb()} ${faker.hacker.noun()}`; - }, - description: faker.hacker.phrase, - category: pickOne(CATEGORIES), - currentUserPermissions: pickOne(PERMISSIONS), - - fork: faker.random.boolean, - collection: faker.random.boolean, - registration: faker.random.boolean, - public: faker.random.boolean, - - dateCreated: faker.date.past, - dateModified: function() { - return faker.date.between(this.dateCreated, new Date()); - }, - - tags: function() { - return [ - faker.company.catchPhraseNoun(), - faker.company.catchPhraseNoun(), - faker.company.catchPhraseNoun() - ]; - } -}); diff --git a/tests/dummy/mirage/factories/registration.js b/tests/dummy/mirage/factories/registration.js deleted file mode 100644 index 2e878248c..000000000 --- a/tests/dummy/mirage/factories/registration.js +++ /dev/null @@ -1,45 +0,0 @@ -import { - faker -} from 'ember-cli-mirage'; - -import NodeFactory from './node'; - -export default NodeFactory.extend({ - dateRegistered: faker.date.past, - embargoEndDate: faker.date.future, - - pendingRegistrationApproval: faker.random.boolean, - pendingEmbargoApproval: function() { - if (this.pendingRegistrationApproval) { - return false; - } - return faker.random.boolean(); - }, - - withdrawn: function() { - if (this.pendignRegistrationApproval || this.pendingEmbargoApproval) { - return false; - } - return faker.random.boolean(); - }, - withdrawalJustification: function() { - if (this.withdrawn) { - return faker.hacker.phrase(); - } - return null; - }, - pendingWithdrawal: function() { - if (!(this.pendignRegistrationApproval || this.pendingEmbargoApproval) && !this.withdrawn) { - return faker.random.boolean(); - } - return false; - }, - - registrationSupplement: function() { - return `${faker.hacker.adjective()} Preregistration (${faker.name.lastName} et al., ${faker.date.past().getFullYear()}`; - }, - registeredMeta: function() { - // TODO - return {}; - } -}); diff --git a/tests/dummy/mirage/factories/user.js b/tests/dummy/mirage/factories/user.js deleted file mode 100644 index bb44c2dde..000000000 --- a/tests/dummy/mirage/factories/user.js +++ /dev/null @@ -1,14 +0,0 @@ -import { - Factory, - faker -} from 'ember-cli-mirage'; - -export default Factory.extend({ - givenName: faker.name.firstName, - middleNames: faker.name.firstName, - familyName: faker.name.lastName, - fullName: function() { - return `${this.givenName} ${this.middleNames} ${this.familyName}`; - }, - dateRegistered: faker.date.past -}); diff --git a/tests/dummy/mirage/models/contributor.js b/tests/dummy/mirage/models/contributor.js deleted file mode 100644 index 483522030..000000000 --- a/tests/dummy/mirage/models/contributor.js +++ /dev/null @@ -1,8 +0,0 @@ -import { - Model, - belongsTo -} from 'ember-cli-mirage'; - -export default Model.extend({ - user: belongsTo('user') -}); diff --git a/tests/dummy/mirage/models/institutions.js b/tests/dummy/mirage/models/institutions.js deleted file mode 100644 index ce7234d07..000000000 --- a/tests/dummy/mirage/models/institutions.js +++ /dev/null @@ -1,16 +0,0 @@ -import { - Model, - hasMany -} from 'ember-cli-mirage'; - -export default Model.extend({ - users: hasMany('users', { - inverseOf: 'affiliatedInstitutions' - }), - nodes: hasMany('nodes', { - inverseOf: 'affiliatedInstitutions' - }), - registrations: hasMany('registrations', { - inverseOf: 'affiliatedInstitutions' - }) -}); diff --git a/tests/dummy/mirage/models/logs.js b/tests/dummy/mirage/models/logs.js deleted file mode 100644 index 008e2d077..000000000 --- a/tests/dummy/mirage/models/logs.js +++ /dev/null @@ -1,12 +0,0 @@ -import { - Model, - belongsTo -} from 'ember-cli-mirage'; - -export default Model.extend({ - node: belongsTo('node'), - originalNode: belongsTo('node'), - user: belongsTo('user'), - linkedNode: belongsTo('node'), - templateNode: belongsTo('node') -}); diff --git a/tests/dummy/mirage/models/node.js b/tests/dummy/mirage/models/node.js deleted file mode 100644 index 0683fd884..000000000 --- a/tests/dummy/mirage/models/node.js +++ /dev/null @@ -1,26 +0,0 @@ -import { - Model, - belongsTo, - hasMany -} from 'ember-cli-mirage'; - -export default Model.extend({ - parent: belongsTo('node'), - children: hasMany('nodes', { - inverseOf: 'parent' - }), - affiliatedInstitutions: hasMany('institutions', { - inverseOf: 'nodes' - }), - contributors: hasMany('contributors'), - - // comments: hasMany('comments'), - //files: DS.hasMany('files'), - forkedFrom: belongsTo('node'), - //nodeLinks: DS.hasMany('node-pointers'), - registrations: hasMany('registrations', { - inverseOf: 'registeredFrom' - }), - - root: belongsTo('node') -}); diff --git a/tests/dummy/mirage/models/registration.js b/tests/dummy/mirage/models/registration.js deleted file mode 100644 index 14750c8c7..000000000 --- a/tests/dummy/mirage/models/registration.js +++ /dev/null @@ -1,13 +0,0 @@ -import { - belongsTo, - hasMany -} from 'ember-cli-mirage'; - -import NodeMirageModel from './node'; - -export default NodeMirageModel.extend({ - registeredFrom: belongsTo('node'), - registeredBy: belongsTo('user'), - contributors: hasMany('contributors') - // comments: hasMany('comments') -}); diff --git a/tests/dummy/mirage/models/user.js b/tests/dummy/mirage/models/user.js deleted file mode 100644 index a23068b02..000000000 --- a/tests/dummy/mirage/models/user.js +++ /dev/null @@ -1,12 +0,0 @@ -import { - Model, - hasMany -} from 'ember-cli-mirage'; - -export default Model.extend({ - nodes: hasMany('nodes'), - registrations: hasMany('registrations'), - affiliatedInstitutions: hasMany('institutions', { - inverseOf: 'users' - }) -}); diff --git a/tests/dummy/mirage/scenarios/default.js b/tests/dummy/mirage/scenarios/default.js deleted file mode 100644 index c5e299f13..000000000 --- a/tests/dummy/mirage/scenarios/default.js +++ /dev/null @@ -1,11 +0,0 @@ -export default function( /* server */ ) { - - /* - Seed your development database using your factories. - This data will not be loaded in your tests. - - Make sure to define a factory for each model you want to create. - */ - - // server.createList('post', 10); -} diff --git a/tests/dummy/mirage/serializers/application.js b/tests/dummy/mirage/serializers/application.js deleted file mode 100644 index b4852fe6b..000000000 --- a/tests/dummy/mirage/serializers/application.js +++ /dev/null @@ -1,4 +0,0 @@ -import JSONAPISerializer from 'ember-cli-mirage'; - -export default JSONAPISerializer.extend({ -}); diff --git a/tests/dummy/mirage/util.js b/tests/dummy/mirage/util.js deleted file mode 100644 index 5e3c321a9..000000000 --- a/tests/dummy/mirage/util.js +++ /dev/null @@ -1,7 +0,0 @@ -export default { - pickOne: function(list) { - return function() { - return list[Math.floor(Math.random() * list.length)]; - }; - } -}; From f5cf31a4653137e0491c6b758a4208aedff19089 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 25 May 2016 14:22:15 -0400 Subject: [PATCH 318/959] Pass tests --- addon/components/file-chooser/component.js | 20 +++++++++---------- addon/components/file-chooser/template.hbs | 2 +- tests/dummy/app/routes/prereg.js | 4 +--- .../components/file-chooser/component-test.js | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/addon/components/file-chooser/component.js b/addon/components/file-chooser/component.js index 304bbc2b3..60059ac8b 100644 --- a/addon/components/file-chooser/component.js +++ b/addon/components/file-chooser/component.js @@ -8,16 +8,16 @@ import layout from './template'; * drag-and-drop, a file browser, or whatever method the developer wants. * * Exposed to parent context (bindable attributes) + * - `files`: mutable list of chosen File objects * - `onChoose`: function called each time a file is added, with the new File * object as the only argument - * - `files`: mutable list of chosen File objects * * Exposed to block context * - `this`: the component object itself, so the block can invoke actions * * Actions - * - `onFileInputChange`: action to handle files chosen through a file input - * - `onChooseFile`: if you use a different way + * - `onFileInputChange`: handle the `change` event on a file input + * - `onChooseFile`: add a file to the chosen list * * Styling * - This component's element has the `drop-zone` class @@ -54,13 +54,9 @@ export default Ember.Component.extend({ drop(event) { event.preventDefault(); this.set('dropZoneReady', false); - let callback = this.get('onChoose'); for (let i = 0; i < event.dataTransfer.files.length; i++) { let file = event.dataTransfer.files[i]; - let p = this._fileCheck(file); - p.then(() => this.send('onChooseFile', file, callback)); - p.catch(() => this.set('errorMessage', - `Cannot upload directories (${file.name})`)); + this._chooseIfFile(file); } }, @@ -87,15 +83,19 @@ export default Ember.Component.extend({ } }, - _fileCheck(file) { + _chooseIfFile(file) { // HACK: There's not a cross-browser way to see the contents of // dragged-and-dropped directories, but there's also not a good way to // tell whether a given File object is a directory. Hence, this: - return new Promise(function(resolve, reject) { + let p = new Ember.RSVP.Promise(function(resolve, reject) { let reader = new FileReader(); reader.onload = () => resolve(); // it's a file reader.onerror = () => reject(); // it's a directory or something reader.readAsText(file.slice(0, 5)); }); + let callback = this.get('onChoose'); + p.then(() => this.send('onChooseFile', file, callback)); + p.catch(() => this.set('errorMessage', + `Cannot upload directories (${file.name})`)); } }); diff --git a/addon/components/file-chooser/template.hbs b/addon/components/file-chooser/template.hbs index e7672aa78..64ff8aca7 100644 --- a/addon/components/file-chooser/template.hbs +++ b/addon/components/file-chooser/template.hbs @@ -2,7 +2,7 @@ {{yield this}} {{else}}

    - {{input type='file' change=(action 'onFileInputChange')}} + {{input type='file' multiple=true change=(action 'onFileInputChange')}}

    You can also drag and drop a file from your computer. diff --git a/tests/dummy/app/routes/prereg.js b/tests/dummy/app/routes/prereg.js index 08b65ca99..831de404e 100644 --- a/tests/dummy/app/routes/prereg.js +++ b/tests/dummy/app/routes/prereg.js @@ -5,12 +5,10 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { fileManager: Ember.inject.service(), actions: { preregister(name, files) { - let store = this.get('store'); - let fileNames = files.mapBy('name').join(', '); // TODO: This page is just a file-chooser demo at this point - alert(`Files: ${fileNames}`); + window.alert(`Files: ${fileNames}`); // store.createRecord('node', { title: name, ... }) diff --git a/tests/integration/components/file-chooser/component-test.js b/tests/integration/components/file-chooser/component-test.js index 5d0fc4b12..a7bf9a74a 100644 --- a/tests/integration/components/file-chooser/component-test.js +++ b/tests/integration/components/file-chooser/component-test.js @@ -11,7 +11,7 @@ test('it renders', function(assert) { this.render(hbs`{{file-chooser}}`); - assert.equal(this.$().text().trim(), ''); + assert.equal(this.$().text().trim(), 'You can also drag and drop a file from your computer.'); // Template block usage: this.render(hbs` From a747ba2af7d8d337afb388454fe97c76370dd8e7 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 25 May 2016 14:32:41 -0400 Subject: [PATCH 319/959] Fix style errors --- addon/components/file-chooser/component.js | 10 +++++----- app/components/file-chooser/component.js | 2 +- tests/dummy/app/components/file-actions/component.js | 2 +- tests/dummy/app/routes/prereg.js | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/addon/components/file-chooser/component.js b/addon/components/file-chooser/component.js index 60059ac8b..91a376a20 100644 --- a/addon/components/file-chooser/component.js +++ b/addon/components/file-chooser/component.js @@ -14,6 +14,11 @@ import layout from './template'; * * Exposed to block context * - `this`: the component object itself, so the block can invoke actions + * example: + * {{#file-chooser files=fileList as |component|}} + * {{input type='file' + * change=(action 'onFileInputChange' target=component)}} + * {{/file-chooser}} * * Actions * - `onFileInputChange`: handle the `change` event on a file input @@ -23,11 +28,6 @@ import layout from './template'; * - This component's element has the `drop-zone` class * - While the user is holding dragged files over this component, it * has the `drop-zone-ready` class - * - * {{#file-chooser files=fileList as |component|}} - * {{input type='file' - * change=(action 'onFileInputChange' target=component)}} - * {{/file-chooser}} */ export default Ember.Component.extend({ diff --git a/app/components/file-chooser/component.js b/app/components/file-chooser/component.js index d574a2612..192315de5 100644 --- a/app/components/file-chooser/component.js +++ b/app/components/file-chooser/component.js @@ -1 +1 @@ -export { default } from 'ember-osf/components/file-chooser/component'; \ No newline at end of file +export { default } from 'ember-osf/components/file-chooser/component'; diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index e82666f4c..0975573d4 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -36,7 +36,7 @@ export default Ember.Component.extend({ uploadFiles(files) { let fm = this.get('fileManager'); let folder = this.get('file'); - while(files && files.length) { + while (files && files.length) { let file = files.pop(); fm.uploadFile(folder, file.name, file).then(() => { this.get('onChange')(); diff --git a/tests/dummy/app/routes/prereg.js b/tests/dummy/app/routes/prereg.js index 831de404e..ab8ac5d68 100644 --- a/tests/dummy/app/routes/prereg.js +++ b/tests/dummy/app/routes/prereg.js @@ -11,7 +11,6 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { window.alert(`Files: ${fileNames}`); // store.createRecord('node', { title: name, ... }) - // for (let file of files) { // this.get('fileManager').uploadFile(...) // } From 3fb44e9644d2b9d129292accc53a158faa9c9139 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 25 May 2016 14:35:24 -0400 Subject: [PATCH 320/959] Remove duplicate log display [skip ci] --- tests/dummy/app/templates/nodes/detail/index.hbs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/dummy/app/templates/nodes/detail/index.hbs b/tests/dummy/app/templates/nodes/detail/index.hbs index 118115e97..bd8b9a919 100644 --- a/tests/dummy/app/templates/nodes/detail/index.hbs +++ b/tests/dummy/app/templates/nodes/detail/index.hbs @@ -73,6 +73,4 @@

    Files

    {{link-to 'View Files' 'nodes.detail.files' model class='btn btn-primary'}} -
    - {{log-detail node-logs=model.logs}} From 8c39b61493e21cdd62d408613606ae5fd68efc77 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 25 May 2016 15:32:08 -0400 Subject: [PATCH 321/959] Use file-chooser for updating file contents --- addon/components/file-chooser/component.js | 22 ++++++++++++------- addon/components/file-chooser/template.hbs | 3 ++- .../app/components/file-actions/component.js | 3 +-- .../app/components/file-actions/template.hbs | 12 ++++++---- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/addon/components/file-chooser/component.js b/addon/components/file-chooser/component.js index 91a376a20..2f6886b3f 100644 --- a/addon/components/file-chooser/component.js +++ b/addon/components/file-chooser/component.js @@ -9,8 +9,10 @@ import layout from './template'; * * Exposed to parent context (bindable attributes) * - `files`: mutable list of chosen File objects - * - `onChoose`: function called each time a file is added, with the new File - * object as the only argument + * - `multiple`: boolean (default `true`), when `false`, only keeps the most + * recently chosen File in the list + * - `onChoose`: callback function called each time a file is added, with the + * new File object as the only argument * * Exposed to block context * - `this`: the component object itself, so the block can invoke actions @@ -35,6 +37,7 @@ export default Ember.Component.extend({ classNames: ['drop-zone'], classNameBindings: ['dropZoneReady'], dropZoneReady: false, + multiple: true, dragOver(event) { if (event.dataTransfer.types.indexOf('Files') > -1) { @@ -64,19 +67,23 @@ export default Ember.Component.extend({ onFileInputChange(event) { for (let i = 0; i < event.target.files.length; i++) { let file = event.target.files[i]; - let callback = this.get('onChoose'); - this.send('onChooseFile', file, callback); + this.send('onChooseFile', file); } }, - onChooseFile(file, callback) { + onChooseFile(file) { let files = this.get('files'); if (typeof files === 'undefined') { this.set('files', Ember.A()); files = this.get('files'); } - files.pushObject(file); + if (this.get('multiple')) { + files.pushObject(file); + } else { + this.set('files', Ember.A([file])); + } + let callback = this.get('onChoose'); if (callback) { callback(file); } @@ -93,8 +100,7 @@ export default Ember.Component.extend({ reader.onerror = () => reject(); // it's a directory or something reader.readAsText(file.slice(0, 5)); }); - let callback = this.get('onChoose'); - p.then(() => this.send('onChooseFile', file, callback)); + p.then(() => this.send('onChooseFile', file)); p.catch(() => this.set('errorMessage', `Cannot upload directories (${file.name})`)); } diff --git a/addon/components/file-chooser/template.hbs b/addon/components/file-chooser/template.hbs index 64ff8aca7..1061999b9 100644 --- a/addon/components/file-chooser/template.hbs +++ b/addon/components/file-chooser/template.hbs @@ -2,7 +2,8 @@ {{yield this}} {{else}}

    - {{input type='file' multiple=true change=(action 'onFileInputChange')}} + {{input type='file' multiple=multiple + change=(action 'onFileInputChange')}}

    You can also drag and drop a file from your computer. diff --git a/tests/dummy/app/components/file-actions/component.js b/tests/dummy/app/components/file-actions/component.js index 0975573d4..a3d4e3a94 100644 --- a/tests/dummy/app/components/file-actions/component.js +++ b/tests/dummy/app/components/file-actions/component.js @@ -13,8 +13,7 @@ export default Ember.Component.extend({ window.open(url); }, - updateContents(evt) { - let contents = evt.target.files[0]; + updateContents(contents) { let file = this.get('file'); let fm = this.get('fileManager'); diff --git a/tests/dummy/app/components/file-actions/template.hbs b/tests/dummy/app/components/file-actions/template.hbs index 321d0a091..6e2f004cb 100644 --- a/tests/dummy/app/components/file-actions/template.hbs +++ b/tests/dummy/app/components/file-actions/template.hbs @@ -14,10 +14,10 @@ - + Delete: - + @@ -78,7 +78,10 @@ {{else}} - + + Download: + + @@ -89,7 +92,8 @@ Update file contents: - {{input type='file' change=(action 'updateContents')}} + {{file-chooser multiple=false + onChoose=(action 'updateContents')}} {{/if}} From b927dd3f0daa818110aa60e6568e420d3d824554 Mon Sep 17 00:00:00 2001 From: Andy Boughton Date: Wed, 25 May 2016 16:55:03 -0400 Subject: [PATCH 322/959] Connect locales and sample translation of signup page [#EOSF-25] [ci skip] --- addon/components/login-form/template.hbs | 14 +++++----- addon/components/sign-up/template.hbs | 22 +++++++-------- app/locales/en-us/translations.js | 35 ++++++++++++++++++------ tests/dummy/config/environment.js | 3 ++ 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/addon/components/login-form/template.hbs b/addon/components/login-form/template.hbs index 3e99dd8b3..d75afa2d9 100644 --- a/addon/components/login-form/template.hbs +++ b/addon/components/login-form/template.hbs @@ -1,27 +1,27 @@