Skip to content

Commit

Permalink
Update to current version of mmh
Browse files Browse the repository at this point in the history
Renamed gallery to collection
picture add (view + controller)
image grid
ui tweaks

Signed-off-by: Christian Roth <christian.roth@port17.de>
  • Loading branch information
cr0 committed Aug 11, 2013
1 parent e80feda commit b6fa31c
Show file tree
Hide file tree
Showing 71 changed files with 885 additions and 313 deletions.
11 changes: 9 additions & 2 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ module.exports = (grunt) ->
'public/js/templates/search.js': 'assets/tpl/search.jade'
'public/js/templates/search-item.js': 'assets/tpl/search-item.jade'

'public/js/templates/gallery.js': 'assets/tpl/gallery.jade'
'public/js/templates/gallery-item.js': 'assets/tpl/gallery-item.jade'
'public/js/templates/gallery.js': 'assets/tpl/gallery/index.jade'
'public/js/templates/gallery-item.js': 'assets/tpl/gallery/item.jade'
'public/js/templates/gallery-new.js': 'assets/tpl/gallery/new.jade'

'public/js/templates/picture-new.js': 'assets/tpl/picture/new.jade'
'public/js/templates/picture-upload.js': 'assets/tpl/picture/upload.jade'
'public/js/templates/picture-collections.js': 'assets/tpl/picture/collections.jade'
'public/js/templates/picture-collection.js': 'assets/tpl/picture/collection.jade'
'public/js/templates/picture-tool.js': 'assets/tpl/picture/tool.jade'

'public/js/templates/setting.js': 'assets/tpl/setting.jade'

Expand Down
57 changes: 57 additions & 0 deletions app/controllers/CollectionController.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

Mmh = require('mmh')

Collection = require '../models/Collection'


module.exports = class CollectionController extends Mmh.RestController

get: ( req, res, next ) ->
if req.params.id
Collection.findById req.params.id, (err, collection) ->
if err then return next new Error err
if not collection then return next new Mmh.Error.NotFound "No collection with id #{req.params.id}"
res.json collection
else
Collection.find (err, collections) ->
if err then return next new Error err
res.json collections


post: ( req, res, next ) ->

# delete read only props
delete req.body.type
delete req.body.user

collection = new Collection req.body

collection.user._id = req.user._id
collection.user.name = req.user.name

collection.save (err) ->
if err then return next new Error err
res.json collection


put: ( req, res, next ) ->
Collection.findById req.params.id, (err, collection) ->
if err then return next new Error err

collection.name = req.body.name
collection.location = req.body.location
collection.tags = req.body.tags

collection.save (err) ->
if err then return next new Error err
res.json collection


delete: ( req, res, next ) ->
Collection.findById req.params.id, (err, collection) ->
if err then return next new Error err

collection.delete (err) ->
if err then return next new Error err
res.json code: 'ok'

56 changes: 0 additions & 56 deletions app/controllers/GalleryController.coffee

This file was deleted.

37 changes: 37 additions & 0 deletions app/models/Collection.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

mongoose = require 'mongoose'
textSearch = require 'mongoose-text-search'


CollectionSchema = new mongoose.Schema

type:
type: String
default: 'collection'
select: false

name:
type: String
required: true
unique: true

description: String

user:
_id:
type: mongoose.Schema.Types.ObjectId
ref: 'User'
name: String

pictures:
type: [mongoose.Schema.Types.ObjectId]
ref: 'Picture'

tags:
type: [String]
index: 'text'


CollectionSchema.plugin textSearch

module.exports = Collection = mongoose.model 'Collection', CollectionSchema
37 changes: 10 additions & 27 deletions app/models/Gallery.coffee → app/models/Picture.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ PictureSchema = new mongoose.Schema
select: false

sources:
thumb:
type: String
required: true

low:
type: String
required: true
Expand All @@ -44,36 +48,15 @@ PictureSchema = new mongoose.Schema
ref: 'User'
name: String


GallerySchema = new mongoose.Schema

type:
type: String
default: 'gallery'
select: false

name:
type: String
required: true
unique: true

location:
type: [Number]
index: '2d'

user:
_id:
type: mongoose.Schema.Types.ObjectId
ref: 'User'
name: String

pictures: [PictureSchema]

tags:
type: [String]
index: 'text'

collections:
type: [mongoose.Schema.Types.ObjectId]
ref: 'Collection'


GallerySchema.plugin textSearch
PictureSchema.plugin textSearch

module.exports = Gallery = mongoose.model 'Gallery', GallerySchema
module.exports = Picture = mongoose.model 'Picture', PictureSchema
2 changes: 1 addition & 1 deletion assets/coffee/controllers/base/controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ define [
@compose 'site', SekeltonView
@compose 'imprint', ImprintView, region: 'imprint'
@compose 'login', LoginView, region: 'login'
@compose 'error', ErrorView, region: 'dynamic'
@compose 'error', ErrorView, region: 'error'



47 changes: 47 additions & 0 deletions assets/coffee/controllers/collection-controller.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
define (require) ->
'use strict'

$ = require 'jquery'
utils = require 'lib/utils'
AuthController = require 'controllers/base/auth-controller'
Collection = require 'models/collection'

CollectionView = require 'views/collection/index-view'
CollectionItemsView = require 'views/collection/items-view'
NewCollectionView = require 'views/collection/new-view'

class CollectionController extends AuthController

show: (params) ->
@adjustTitle 'Collection'

@collection = new Collection _id: params.id
@collection.fetch
success: (collection) =>
@pictures = @collection.get('pictures')
@pictures.id = '1234'
@pictures.add id: num, url: "//lorempixel.com/1600/1200/?r=#{num}" for num in [1..40]

@search = new CollectionView
model: @gallery
region: 'gallery'

@pictures = new CollectionItemsView
collection: @pictures
region: 'images'
preload: params.preload ? 10

utils.pageTransition $('#gallery'), 'right'

error: (collection, error) =>
@publishEvent '!error', error


create: (params) ->
@adjustTitle 'a/Collection'

@view = new NewCollectionView
region: 'dynamic'

utils.pageTransition $('#dynamic'), 'top'

31 changes: 0 additions & 31 deletions assets/coffee/controllers/gallery-controller.coffee

This file was deleted.

8 changes: 4 additions & 4 deletions assets/coffee/controllers/hello-controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ define [
'chaplin'
'lib/utils'
'controllers/base/auth-controller'
'models/gallery-collection'
'models/collections'
'views/search/search-view'
'views/search/items-view'
], ($, Chaplin, utils, AuthController, GalleryCollection, SearchView, SearchItemsView) ->
], ($, Chaplin, utils, AuthController, Collections, SearchView, SearchItemsView) ->
'use strict'

class HelloController extends AuthController

show: (params) ->
@adjustTitle 'Hello'

collection = new GalleryCollection
collection.add id: num, name: "gallery #{num}" for num in [1..6]
collection = new Collections
collection.add id: num, name: "gallery #{num}" for num in [1..8]

@search = new SearchView
model: Chaplin.mediator.user
Expand Down
25 changes: 25 additions & 0 deletions assets/coffee/controllers/picture-controller.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
define (require) ->
'use strict'

$ = require 'jquery'
utils = require 'lib/utils'

AuthController = require 'controllers/base/auth-controller'
Collections = require 'models/collections'
NewPictureView = require 'views/picture/new-view'


class PictureController extends AuthController

create: (params) ->
@adjustTitle 'a/Picture'

collections = new Collections
collections.fetch()

@view = new NewPictureView
region: 'dynamic'
collection: collections

utils.pageTransition $('#dynamic'), 'top'

7 changes: 7 additions & 0 deletions assets/coffee/lib/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ define [

if !support then onEndAnimation $out, $in

formatFileSize: (bytes)->
if typeof bytes is not 'number' then return ''

if bytes >= 1000000000 then return "#{(bytes / 1000000000).toFixed(2)} GB"
else if bytes >= 1000000 then return "#{(bytes / 1000000).toFixed(2)} MB"
else if bytes >= 1000 then return "#{(bytes / 1000).toFixed(2)} KB"

utils
Loading

0 comments on commit b6fa31c

Please sign in to comment.