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

[WIP][DO NOT MERGE]Album feature #339

Open
wants to merge 2 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
46 changes: 46 additions & 0 deletions forms/add-images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var fields = [];
fields.push({
label: "Album Name",
name:"album-name",
placeholder: "E.g: FOB,SPONS",
editable: true,
type: "select",
options: ["FOB", "SPONSORS"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You sure about using a "select" here? Also, I suggest we keep such identifier names consistent by enforcing lowercase and hyphen separated strings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. They don't have any other option , neither can they write it on their own.

value: "",
typeahead: false,
none: true,
});
fields.push({
label: "Image",
name:"image",
editable: true,
type: "image",
required: true,
value: "",
typeahead: false,
none: true,
width: 800,
height: 400,
id: 1
});
fields.push({
label: "Title",
name:"title",
editable: true,
type: "textarea",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Titles probably shouldn't be multiline.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cons of making in multi-line ?

required: false,
value: "",
typeahead: false,
none: true
});
fields.push({
label: "Sub-title",
name:"subtitle",
editable: true,
type: "textarea",
required: false,
value: "",
typeahead: false,
none: true
});
module.exports = fields;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline thingy.

36 changes: 36 additions & 0 deletions public/static/scripts/add-images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$(document).ready(function() {
$("#submit-button").on('click', function() {
if(!$("#field-image").val()) {
swal({
title: "Please fill image",
type: "error"
});
} else {
$.ajax({
type: 'POST',
url: '/api/images',
data: {
album: $('#field-album-name').val(),
title: $('#field-title').val(),
subtitle: $('#field-subtitle').val() || "",
image: $("#field-image").val(),
path: $("#image-editor-1").attr("value")
}
}).done(function (data) {
swal({
title: "Successful",
type: "success",
confirmButtonText: "OK",
});
}).fail(function (err) {
swal({
title: "Some error occurred",
text: JSON.stringify(err),
type: "error",
confirmButtonText: "OK",
});
});
}
});

});
1 change: 1 addition & 0 deletions routes/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services.push(require('./services/accomm'));
services.push(require('./services/bodies'));
services.push(require('./services/feed'));
services.push(require('./services/news'));
services.push(require('./services/images'));

services.forEach(function (service) {
router.use(service.route, constructor(service.model, service.router, service.permission));
Expand Down
45 changes: 45 additions & 0 deletions routes/api/services/images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var express = require("express");
var router = express.Router();
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var fs = require("fs");

var imageSchema = new Schema({
albumname: String,
title: String,
subtitle: String,
img: String
});
var model = mongoose.model('images', imageSchema);


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many blank lines?


router.post("/", function(req, res, next) {
var album = (req.body.album).trim();
var title = (req.body.title).trim();
var subtitle = (req.body.subtitle).trim();
var imagePath = (req.body.path).trim();
var imageName = imagePath.split("/")[4];

var imageModel = new model({
albumname: album,
title: title,
subtitle: subtitle,
img: imageName
});
imageModel.save();
return res.json(req.body);
});
var permission = {
read_one: 0,
read_all: 0,
insert: 1,
update: 2,
delete: 2
};
module.exports = {
route: '/images',
router: router,
model: model,
permission: permission
};
45 changes: 45 additions & 0 deletions routes/components/addimages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var express = require('express');
var router = express.Router();
var fq = require('fuzzquire');
var middleware = fq("authentication").middleware;
var fields = fq("forms/add-images");

var applyStateChanges = function (req, superuser) {
req.stateparams.title = {
text: 'Images',
route: '/images',
};
if (superuser)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Braces around the if block.

req.stateparams.submenu = [{
route: "/addimages/new",
label: "Add new images for an album",
}
];
return req;
};
router.get("/", middleware.authenticate, middleware.elevate, function(req, res, next) {
if(req.user.privilege.level == 2) {
req = applyStateChanges(req, true);
req.stateparams.pagetitle = 'Add Images for Album.';
res.renderState('add-images/home', {
user: req.user,
title: 'Add Images for Album.'
});
} else if (req.user.privilege.level == 1) {
req = applyStateChanges(req, false);
res.redirect('/');
}
});
router.get("/new", middleware.authenticate, middleware.elevate, function(req, res, next) {
if(req.user.privilege.level == 2) {
res.renderState('add-images/album', {
user:req.user,
title: 'Add Images for Album',
fields: fields
});
} else if( req.user.privilege.level == 1) {
req = applyStateChanges(req, false);
res.redirect('/');
}
});
module.exports = router;
2 changes: 1 addition & 1 deletion routes/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ router.get('/', function (req, res, next) {
});

router.use('/', fq('components/custom'));
let routes = ['events', 'dashboard', 'portals', 'about', 'ca', 'login'];
let routes = ['events', 'dashboard', 'portals', 'about', 'ca', 'login', 'addimages'];
routes.forEach(elem => {
router.use(`/${elem}`, fq(`components/${elem}`));
});
Expand Down
10 changes: 10 additions & 0 deletions views/add-images/album.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include ../mixins/form
script(type="text/javascript" src="/static/lib/jquery.uploadPreview.min.js")
.immersive-wrapper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure about using immersive-wrapper here? Use generic div instead, as immersive CSS might sometime later cause this particular page to look out of place from the rest of the portals.

#add-images-album-wrapper
- var form = { fields: fields, method: "PUT", action: "/api/users/me"};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental remnant of copy-paste in the action field. Put as blank or remove it completely, I suppose, since AJAX is handling it.

+formMixin(form)
#submit-button
button Submit
script(src="/static/scripts/add-images.js")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace.

2 changes: 2 additions & 0 deletions views/add-images/home.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.immersive-wrapper
| Hi this is hello code.
3 changes: 2 additions & 1 deletion views/mixins/img-upload.jade
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ mixin imgUpload(data)
input(type="file" required=data.required id="field-#{data.name}" name="field-#{data.name}" class="cropit-image-input")
div(class="cropit-preview", id="cropit-preview-#{data.id}")
div.status
i.icon-check.response(id="export-img-#{data.id}")
i.icon-check.response(id="export-img-#{data.id}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace.

label(for="field-#{data.name}" id="label-#{data.name}")
i.icon-add_a_photo
script(src="/static/scripts/image-upload-mixin.js")
script.
imgCropInit({
input: "field-#{data.name}",
Expand Down