Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/create tags for activity result #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/activityresults/activityresult.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ var ld = require('lodash');
var ActivityResult = function ActivityResult(data) {
var _this = this;

this.tags = [];
this.photos = [];

if (data) {
this.id = data.id;
this.created_by = data.created_by;
this.photos = data.photos;
this.photos = data.photos || [];
this.tags = data.tags || [];
}

this.getPhotoById = function getPhotoById(id) {
Expand Down
4 changes: 3 additions & 1 deletion lib/activityresults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ app.post('/', function (req, res) {
if (!activityResultName) {
return res.send(BAD_REQUEST);
}
activityresultsPersistence.save(new ActivityResult({id: activityResultName, created_by: req.user.member.id }), function (err) {
var tags = (req.body.tags || "").split(',');

activityresultsPersistence.save(new ActivityResult({id: activityResultName, tags: tags, created_by: req.user.member.id }), function (err) {
if (err) {
return res.send(BAD_REQUEST);
}
Expand Down
13 changes: 4 additions & 9 deletions lib/activityresults/views/edit_photo.jade
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@ block content
.col-md-4
h4 Step #2: Pick a room
ul.tag-list
li
input#tag-hopper(type="radio",name="tag",value="hopper")
label.btn.btn-default(for="tag-hopper") # Hopper
li
input#tag-lovelace(type="radio",name="tag",value="lovelace")
label.btn.btn-default(for="tag-lovelace") # Lovelace
li
input#tag-liskov(type="radio",name="tag",value="liskov")
label.btn.btn-default(for="tag-liskov") # Liskov
each availableTag, i in activityResult.tags
li
input(type="radio",name="tag",value=availableTag,id="tag-"+i)
label.btn.btn-default(for="tag-" + i) # #{availableTag}
.row
.col-md-8
h4 Step #3: What's on that photo?
Expand Down
7 changes: 6 additions & 1 deletion lib/activityresults/views/notFound.jade
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ block content
form(role='form',method='POST',action=createUri)
+csrf
.form-group
input(name='activityResultName',type='hidden',value='#{activityResultName}')
label(for='inputName') Name
input.form-control#inputName(name='activityResultName',type='text',readonly='readonly',value='#{activityResultName}')
.form-group
label(for='inputTag') Tags (comma-separated)
input.form-control#inputTags(name='tags',type='text')
.form-group
button.btn.btn-primary(type='submit') Jetzt anlegen
4 changes: 4 additions & 0 deletions test/activityresults/activityresult_model_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ describe('Activity result', function () {
expect(new ActivityResult({created_by: 'me'})).to.have.property('created_by', 'me');
});

it('should have a field of defined tags for an activityResult', function () {
expect(new ActivityResult({tags: ['1', '2']}).tags).to.be.eql(['1', '2']);
});

describe('photo subdocument', function () {
it('should be retrievable by id', function () {
var activityResult = new ActivityResult({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('/activityresults/:result/photo/:photo', function () {
var photoId = 'photo_id';
beforeEach(function () {
sinon.stub(activityresultsService, 'getActivityResultByName', function (activityResultName, callback) {
callback(null, new ActivityResult({ id: "foo", name: "foobar", created_by: 1, photos: [{id: photoId, title: 'mishka', uploaded_by: 1}]}));
callback(null, new ActivityResult({ id: "foo", name: "foobar", created_by: 1, tags: [], photos: [{id: photoId, title: 'mishka', uploaded_by: 1}]}));
});
sinon.stub(activityresultsService, 'addPhotoToActivityResult', function (activityResultName, photo, callback) {
callback();
Expand Down
23 changes: 23 additions & 0 deletions test/activityresults/activityresults_integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var expect = require('must');

var beans = conf.get('beans');
var activityresultsService = beans.get('activityresultsService');
var activityresultsPersistence = beans.get('activityresultsPersistence');

var createApp = require('../../testutil/testHelper')('activityresultsApp').createApp;

Expand Down Expand Up @@ -86,6 +87,28 @@ describe('/activityresults', function () {
.expect(303, done);
});

it('should create a new activity result with tags', function (done) {
var theResult;
sinon.stub(activityresultsPersistence, 'save', function (activityResult, callback) {
theResult = activityResult;
callback(null, activityResult);
});

var app = createApp(1);
request(app)
.post('/')
.type('form')
.send({ activityResultName: "MyActivityResult", tags: 'myFirstTag,mySecondTag' })
.expect(303)
.end(function (err) {
if (err) {
done(err);
}
expect(theResult.tags).to.eql(['myFirstTag', 'mySecondTag']);
done();
});
});

it('should reject request without activityResultName parameter', function (done) {
request(createApp(1))
.post('/')
Expand Down