Skip to content

Commit

Permalink
switch courses to loading via static files only, no pouchdb, courses …
Browse files Browse the repository at this point in the history
…now added via 'public/content/courses', fix tests, version bump to 0.2
  • Loading branch information
Jakeii committed Apr 25, 2016
1 parent e0ad428 commit ac24e92
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ cordova/platforms/wp8/*.suo
cordova/platforms/wp8/*.csproj.user

# funzo
public/courses
public/content/courses
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# Funzo-app 0.1.1
# Funzo-app 0.2.0

[![Build Status](https://travis-ci.org/tunapanda/funzo-app.svg?branch=master)](https://travis-ci.org/tunapanda/funzo-app) [![Join the chat at https://gitter.im/tunapanda/funzo-app](https://badges.gitter.im/tunapanda/funzo-app.svg)](https://gitter.im/tunapanda/funzo-app?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

This is a preview of ember and H5P running as an app inside Phonegap/Cordova.

See [here](https://github.com/tunapanda/funzo-app/wiki/Development-Guide) for information on how to contribute.

Courses during development are added via bower E.G. `bower install tunapanda/funzo-CSE-1000 --save`.

Prefix any new courses with `funzo` to ensure they are added during the build process.
Courses during development are copied to `public/content/courses`, see https://https://github.com/tunapanda/funzo-CSE-1000 for an example course.

## Prerequisites

You will need the following things properly installed on your computer.

* [Git](http://git-scm.com/)
* [Git-LFS](https://github.com/github/git-lfs)
* [Node.js](http://nodejs.org/) (with NPM)
* [Bower](http://bower.io/)
* [Ember CLI](http://www.ember-cli.com/)
Expand All @@ -28,7 +25,6 @@ You will need the following things properly installed on your computer.
* change into the new directory
* `npm install`
* `bower install`
* `bower install [email protected]:tunapanda/funzo-CSE-1000 --save` the demo course (*be sure your github SSH key is loaded!*)

## Running / Development

Expand Down
132 changes: 66 additions & 66 deletions app/pods/application/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,72 @@ import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mi

export default Ember.Route.extend(ApplicationRouteMixin, {
session: Ember.inject.service('session'),
beforeModel() {
return this.store.query('course', { permalink: 'funzo-CSE-1000' }).then((courses) => {
if (!courses.get('length')) {
return new Ember.RSVP.Promise((resolve, reject) => Ember.$.getJSON('courses/funzo-CSE-1000/content.json', (content, status) => {
if (status !== 'success') {
return reject(status);
}
return resolve(content);
}).then((content) => {
let modules = content.modules;
delete content.modules;

let modulePermalinks = modules.map((module) => module.permalink);

let activitys = [];

modules.forEach((module) => {
if (module.activities) {
activitys.push(...module.activities);
let activityPermalinks = module.activities.map((activity) => activity.permalink);
module.activities = activityPermalinks;
} else {
module.activities = [];
}
});

let course = content;

course.modules = modulePermalinks;

let hash = {
course,
modules,
activitys
};

return Ember.RSVP.resolve(this.store.pushPayload(hash));

// let modules = Ember.A(content.modules);
// delete content.modules;

// let course = this.store.createRecord('course', content);

// return course.save().then(() => {
// modules = modules.map((module) => {
// module.course = course;
// let activities = module.activities;

// activities.map((activity) => {
// activity = this.store.createRecord('activity', activity);
// activity.
// });

// return this.store.createRecord('module', module);
// });

// return Ember.RSVP.all(modules.invoke('save'));
// }).then((modules) => {
// course.get('modules').pushObjects(modules);
// return course.save();
// });
}));
}
return Ember.RSVP.resolve();
});
},
// beforeModel() {
// return this.store.query('course', { permalink: 'funzo-CSE-1000' }).then((courses) => {
// if (!courses.get('length')) {
// return new Ember.RSVP.Promise((resolve, reject) => Ember.$.getJSON('courses/funzo-CSE-1000/content.json', (content, status) => {
// if (status !== 'success') {
// return reject(status);
// }
// return resolve(content);
// }).then((content) => {
// let modules = content.modules;
// delete content.modules;

// let modulePermalinks = modules.map((module) => module.permalink);

// let activitys = [];

// modules.forEach((module) => {
// if (module.activities) {
// activitys.push(...module.activities);
// let activityPermalinks = module.activities.map((activity) => activity.permalink);
// module.activities = activityPermalinks;
// } else {
// module.activities = [];
// }
// });

// let course = content;

// course.modules = modulePermalinks;

// let hash = {
// course,
// modules,
// activitys
// };

// return Ember.RSVP.resolve(this.store.pushPayload(hash));

// // let modules = Ember.A(content.modules);
// // delete content.modules;

// // let course = this.store.createRecord('course', content);

// // return course.save().then(() => {
// // modules = modules.map((module) => {
// // module.course = course;
// // let activities = module.activities;

// // activities.map((activity) => {
// // activity = this.store.createRecord('activity', activity);
// // activity.
// // });

// // return this.store.createRecord('module', module);
// // });

// // return Ember.RSVP.all(modules.invoke('save'));
// // }).then((modules) => {
// // course.get('modules').pushObjects(modules);
// // return course.save();
// // });
// }));
// }
// return Ember.RSVP.resolve();
// });
// },

actions: {
back() {
Expand Down
2 changes: 1 addition & 1 deletion app/pods/components/h5p-standalone/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default Ember.Component.extend({
currentUser: Ember.inject.service('currentUser'),

didInsertElement() {
let h5pContent = `courses/${this.get('coursePath')}/modules/${this.get('modulePath')}`;
let h5pContent = `content/courses/${this.get('coursePath')}/modules/${this.get('modulePath')}`;
h5pContent += `/${this.get('activityPath')}`;

let frameJs = 'assets/h5p-standalone-frame.js';
Expand Down
11 changes: 11 additions & 0 deletions app/pods/course/adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
urlForFindAll() {
return 'content/courses/index.json';
},

urlForFindRecord(permalink) {
return `content/courses/${permalink}/content.json`;
}
});
45 changes: 45 additions & 0 deletions app/pods/course/serializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import DS from 'ember-data';

export default DS.RESTSerializer.extend({
primaryKey: 'permalink',
normalizeFindAllResponse(store, primaryModelClass, payload, id, requestType) {
payload = { courses: payload, modules: [], activities: [] };

payload.courses.forEach(course => {
let modules = course.modules;
course.modules = modules.map(module => module.permalink);
payload.modules.push.apply(payload.modules, modules);

modules.forEach(module => {
if (!module.activities) {
return;
}
let activities = module.activities;
module.activities = activities.map(module => module.permalink);
payload.activities.push.apply(payload.activities, activities);
});
});

return this._super(store, primaryModelClass, payload, id, requestType);
},

normalizeFindRecordResponse(store, primaryModelClass, payload, id, requestType) {
let course = payload;
payload = { course: payload, modules: [], activities: [] };

let modules = course.modules;
course.modules = modules.map(module => module.permalink);
payload.modules.push.apply(payload.modules, modules);

modules.forEach(module => {
if (!module.activities) {
return;
}
let activities = module.activities;
module.activities = activities.map(module => module.permalink);
payload.activities.push.apply(payload.activities, activities);
});

return this._super(store, primaryModelClass, payload, id, requestType);
}
});
5 changes: 5 additions & 0 deletions app/pods/module/serializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import DS from 'ember-data';

export default DS.RESTSerializer.extend({
primaryKey: 'permalink'
});
31 changes: 23 additions & 8 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
/*jshint node:true*/
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
// var mergeTrees = require('broccoli-merge-trees');
// var Funnel = require('broccoli-funnel');
var fs = require('fs');

// Create an index of books available at build-time
var coursesDir = 'public/content/courses';
var bookList = fs.readdirSync(coursesDir).map(dir => {
var courseDir = `${coursesDir}/${dir}`;
if (!fs.statSync(courseDir).isDirectory()) {
// TODO: filter out nulls
return;
}
// TODO: catch exceptions and filter out invalid JSON
return JSON.parse(fs.readFileSync(courseDir + '/content.json'));
}).filter(e => e);

fs.writeFileSync(`${coursesDir}/index.json`, JSON.stringify(bookList));

module.exports = function(defaults) {
var app = new EmberApp(defaults, {
Expand All @@ -26,10 +41,10 @@ module.exports = function(defaults) {
}
});

var course = new Funnel('bower_components', {
include: ['funzo-*/**'],
destDir: 'courses/'
});
// var course = new Funnel('bower_components', {
// include: ['funzo-*/**'],
// destDir: 'courses/'
// });

// app.import('bower_components/materialize/dist/css/materialize.css');
app.import('bower_components/tincan/build/tincan.js');
Expand Down Expand Up @@ -61,6 +76,6 @@ module.exports = function(defaults) {
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.
// return app.toTree();
// return app.toTree();
return mergeTrees([app.toTree(), course]);
return app.toTree();
// return mergeTrees([app.toTree(), course]);
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "funzo-app",
"version": "0.1.1",
"version": "0.2.0",
"description": "Small description for funzo-app goes here",
"private": true,
"directories": {
Expand All @@ -24,7 +24,7 @@
"broccoli-jscs": "^1.2.2",
"broccoli-merge-trees": "^1.1.1",
"ember-ajax": "0.7.1",
"ember-cli": "2.3.0",
"ember-cli": "2.5.0",
"ember-cli-app-version": "^1.0.0",
"ember-cli-babel": "^5.1.5",
"ember-cli-cordova": "0.0.17",
Expand Down
24 changes: 0 additions & 24 deletions tests/integration/pods/components/activity-tabs/component-test.js

This file was deleted.

24 changes: 0 additions & 24 deletions tests/integration/pods/components/add-course/component-test.js

This file was deleted.

This file was deleted.

Loading

0 comments on commit ac24e92

Please sign in to comment.