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

Organization Team init #5

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ server/*.js
!app/assets/*/*


app/.idea/*
app/packages/demo/.idea/*
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = function(grunt) {
'generators/**/*.coffee',
'server/*.coffee'
],
tasks: ['sass', 'coffee', 'server']
tasks: ['coffee', 'server']
},

testacular: {
Expand Down
4 changes: 3 additions & 1 deletion app/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ define (require, exports, module) ->

# Packages loading
demoPackage = require 'packages/demo'

orgteamPackage = require 'packages/org-team'

#Utils and other
Utils = require 'shared/utils'

Expand All @@ -17,6 +18,7 @@ define (require, exports, module) ->
initialize: ->
Utils.bindRoutes @, [
demoPackage.Controller
orgteamPackage.Controller
]

unknownRoute: ->
Expand Down
10 changes: 0 additions & 10 deletions app/assets/css/main.css
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
body {
padding-top: 2px;
padding-bottom: 40px; }

.table-users tbody td {
line-height: 36px; }
.table-users tfoot td.pagination-wrap {
background-color: #f8f8f8; }
.table-users tfoot td.pagination-wrap .pagination {
margin: 0px; }
20 changes: 20 additions & 0 deletions app/assets/json/orgs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"id": 1,
"logo": "http://placehold.it/60x60",
"companyName": "Lohika",
"phone": "853-500-3367",
"email": "[email protected]",
"address": "37969, Alaska, Broome Streets",
"about": "Nulla sit tincidunt volutpat enim illum, autem ex iriure hendrerit iriure, volutpat eum vulputate diam. Luptatum, diam ad laoreet dolor commodo, ullamcorper dolore minim commodo ut, elit consequat iusto. Facilisi consequat, esse in vel iusto illum, eros dolor commodo consequat eum, vel dolore. Exerci euismod nisl, delenit ad blandit suscipit dolor, consectetuer dolore ad dolore."
},
{
"id": 2,
"logo": "http://placehold.it/60x60",
"companyName": "Ciklum",
"phone": "841-471-3410",
"email": "[email protected]",
"address": "28272, AmarilloAnaheim, Orchard Street",
"about": "Iusto et feugiat dolore dignissim minim, nulla dignissim molestie dolore dignissim, enim autem vulputate in. Vero, delenit vero commodo sit sed, qui blandit duis consequat vel, velit in et. Suscipit in, nonummy nonummy vulputate facilisis nonummy, at wisi ex duis qui, augue nisl. Velit consequat laoreet, zzril vel consectetuer magna duis, autem laoreet exerci amet nulla, sed. Ea ut dolor ut, wisi accumsan nulla et zzril, tation tation te facilisi zzril, autem sit amet at dolore, ad lobortis elit eros dolore, esse ex nostrud aliquip. Vel, accumsan at in odio diam."
}
]
2 changes: 1 addition & 1 deletion app/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ require.config {
'sinon': 'assets/js/sinon-1.5.2'
},

packages: ['packages/demo', 'packages/organization']
packages: ['packages/demo', 'packages/org-team']
}
5 changes: 0 additions & 5 deletions app/packages/demo/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ define (require, exports, module)->
exports.Controller = class Controller extends BaseController
routes:
'demo': 'demo'
'demo/:id': 'demo'

demo: ->
console.log 'demo'
@currentView = new view.View(
model: new model.Model()
)
$('#demo-box').html @currentView.render().$el
return @
return
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you remove part of demo package?

Copy link
Author

Choose a reason for hiding this comment

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

oo sorry.. i think, it is my phpstorm.. it happened when I was doing the small refactoring

9 changes: 9 additions & 0 deletions app/packages/org-team/collections/collection.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define (require, exports, module) ->
model = require '../models/model'
exports.Collection = Backbone.Collection.extend(
url: ->
'/org'

model: model.Model
)
return
27 changes: 27 additions & 0 deletions app/packages/org-team/main.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
define (require, exports, module)->
orgsView = require './views/organizations'
orgView = require './views/organization'
BaseController = require 'shared/base_controller'

exports.Controller = class Controller extends BaseController
routes:
'org-team': 'getOrgsTeam'
'org-team/:id': 'getOrgTeam'

getOrgsTeam: ->
@orgsView = new orgsView.View
@orgsView.collection.fetch
success: (collection, resp, options) =>
console.dir(collection)
$('#demo-box').html @orgsView.render().el
return @

getOrgTeam: (id)->
@orgView = new orgView.View()
@orgView.model.set {id: id}
@orgView.model.fetch
success: (model, resp, options) =>
$('#demo-box').html @orgView.render().el
return @

return
14 changes: 14 additions & 0 deletions app/packages/org-team/models/model.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
define (require, exports, module) ->
exports.Model = Backbone.Model.extend(
url: ->
"/org/#{@id}"

defaults:
logo: "http://placehold.it/32x32",
companyName: "Test company name",
phone: "",
email: "",
address: "",
about: ""
)
return
12 changes: 12 additions & 0 deletions app/packages/org-team/spec/collection.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
expect = chai.expect

describe 'Test', ->
dep = null

beforeEach (done) ->
require [], (_dep) ->
dep = _dep
done()

it 'should be test', (done) ->
done()
12 changes: 12 additions & 0 deletions app/packages/org-team/spec/main.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
expect = chai.expect

describe 'Test', ->
dep = null

beforeEach (done) ->
require [], (_dep) ->
dep = _dep
done()

it 'should be test', (done) ->
done()
12 changes: 12 additions & 0 deletions app/packages/org-team/spec/model.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
expect = chai.expect

describe 'Test', ->
dep = null

beforeEach (done) ->
require [], (_dep) ->
dep = _dep
done()

it 'should be test', (done) ->
done()
12 changes: 12 additions & 0 deletions app/packages/org-team/spec/view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
expect = chai.expect

describe 'Test', ->
dep = null

beforeEach (done) ->
require [], (_dep) ->
dep = _dep
done()

it 'should be test', (done) ->
done()
24 changes: 24 additions & 0 deletions app/packages/org-team/templates/organization.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="container">
<h2><%= org.companyName%></h2>
<div class="row">
<div class="span12">
<div class="container">
<div class="row">
<div class="span1">
<img src='<%= org.logo%>' alt='<%= org.companyName%>'/>
</div>
<div class="span11">
<ul class='item'>
<li>Phone: <%= org.phone%></a></li>
<li>Email: <%= org.email%></a></li>
<li>Address: <%= org.address%></a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="span12">
<%= org.about%>
</div>
</div>
</div>
12 changes: 12 additions & 0 deletions app/packages/org-team/templates/organizations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="container">
<h2>Organizations</h2>
<div class="row">
<div class="span12">
<ul class='list-item'>
<% _.each(listOrg, function(org) { %>
<li><a href='/#org-team/<%= org.id%>'><%= org.companyName%></a></li>
<% }); %>
</ul>
</div>
</div>
</div>
16 changes: 16 additions & 0 deletions app/packages/org-team/views/organization.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
define (require, exports, module)->
tpl = require 'text!../templates/organization.html'
model = require '../models/model'

exports.View = Backbone.View.extend(
template: _.template tpl
model: new model.Model

initialize: ->

render: ()->
@$el.html @template({org: @model.toJSON()})
return @

)
return
15 changes: 15 additions & 0 deletions app/packages/org-team/views/organizations.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
define (require, exports, module)->
tpl = require 'text!../templates/organizations.html'
collection = require '../collections/collection'

exports.View = Backbone.View.extend(
template: _.template tpl
collection: new collection.Collection

initialize: ->

render: ->
@$el.html @template(listOrg: @collection.toJSON())
return @
)
return
35 changes: 33 additions & 2 deletions app/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

define (require, exports, module) ->
require('sinon')
json =
users: JSON.parse require 'text!assets/json/users.json'

json = {
users: JSON.parse require 'text!assets/json/users.json'
orgs: JSON.parse require 'text!assets/json/orgs.json'
}

_buildResponse = (content, status = 200) ->
[
Expand Down Expand Up @@ -41,6 +44,19 @@ define (require, exports, module) ->
response = _buildResponse JSON.stringify(data), status
xhr.respond.apply xhr, response

_getOrg = (xhr, id) ->
org = null
id = parseInt id
org = _(json.orgs).findWhere {id: id}
if org
data = org
status = 200
else
data = {error: 'Organization not found'}
status = 404
response = _buildResponse JSON.stringify(data), status
xhr.respond.apply xhr, response

_getUsers = (xhr, queryString) ->
params = getQuerySringParams xhr.url
items = json.users.concat (_createUser id for id in [20..100])
Expand All @@ -65,6 +81,11 @@ define (require, exports, module) ->
then 'AUTO_PUBLISH'
else 'MODERATE TOUTS'

_getOrgs = (xhr) ->
data = JSON.stringify(json.orgs)
response = _buildResponse data
xhr.respond.apply xhr, response

requests = [
{
method: 'GET'
Expand All @@ -81,6 +102,16 @@ define (require, exports, module) ->
route: /\/organization\/user\/(\d+)/
response: _getUser
}
{
method: 'GET'
route: '/org'
response: _getOrgs
}
{
method: 'GET'
route: /\/org\/(\d+)/
response: _getOrg
}
]

for req in requests then do (req) ->
Expand Down
2 changes: 1 addition & 1 deletion generators/package/main.coffee.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ define (require, exports, module)->
BaseController = require 'shared/base_controller'

exports.Controller = class Controller extends BaseController
routes:
routes:[]

return
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"node": "~0.6.10 || 0.8 || 0.9"
},
"scripts": {
"test": "node_modules/.bin/testacular start tests/testacular-config.js --single-run --browsers=PhantomJS",
"start": "node_modules/.bin/grunt run"
"test": "node_modules\\.bin\\testacular start tests\\testacular-config.js --single-run --browsers=PhantomJS",
"start": "node_modules\\.bin\\grunt run"
},
"dependencies": {},
"devDependencies": {
Expand Down