@@ -144,5 +143,3 @@ var NoteForm = React.createClass({
)
}
})
-
-module.exports = NoteForm
diff --git a/browser/main/Components/PlanetCreateModal.jsx b/browser/main/Components/PlanetCreateModal.jsx
index 194e8062..8e7336b4 100644
--- a/browser/main/Components/PlanetCreateModal.jsx
+++ b/browser/main/Components/PlanetCreateModal.jsx
@@ -22,9 +22,9 @@ module.exports = React.createClass({
user: currentUser,
planet: {
name: '',
- OwnerId: currentUser.id,
public: true
- }
+ },
+ ownerName: currentUser.name
}
},
componentDidMount: function () {
@@ -36,23 +36,12 @@ module.exports = React.createClass({
}
},
handleSubmit: function () {
- Hq.createPlanet(this.state.user.name, this.state.planet)
+ Hq.createPlanet(this.state.ownerName, this.state.planet)
.then(function (res) {
var planet = res.body
- var currentUser = JSON.parse(localStorage.getItem('currentUser'))
+ PlanetStore.Actions.update(planet)
- var isNew = !currentUser.Planets.some(function (_planet, index) {
- if (planet.id === _planet) {
- currentUser.Planets.splice(index, 1, planet)
- return true
- }
- return false
- })
- if (isNew) currentUser.Planets.push(planet)
-
- localStorage.setItem('currentUser', JSON.stringify(currentUser))
- UserStore.Actions.update(currentUser)
this.props.transitionTo('planetHome', {userName: planet.userName, planetName: planet.name})
this.props.close()
}.bind(this))
@@ -61,14 +50,20 @@ module.exports = React.createClass({
})
},
render: function () {
+ var teamOptions = this.state.user.Teams.map(function (team) {
+ return (
+
+ )
+ })
return (
of
-
)
+ } else if (user.userType === 'team') {
+ return this.renderTeamHome()
} else {
- var userPlanets = user.Planets.map(function (planet) {
- return (
-
- {planet.userName}/{planet.name}
-
- )
- })
-
- var teams = user.Teams == null ? [] : user.Teams.map(function (team) {
- return (
-
- Some team
-
- )
- })
- return (
-
-
-
-
-
{user.profileName}
-
{user.name}
-
-
-
-
-
-
{teams.length} {teams.length > 0 ? 'Teams' : 'Team'}
-
-
-
-
{userPlanets.length} {userPlanets.length > 0 ? 'Planets' : 'Planet'}
-
-
-
- )
+ return this.renderUserHome()
}
} else {
return (
@@ -162,5 +91,120 @@ module.exports = React.createClass({
)
}
+ },
+ renderTeamHome: function () {
+ var user = this.state.user
+
+ var userPlanets = user.Planets.map(function (planet) {
+ return (
+
+ {planet.userName}/{planet.name}
+
+ )
+ })
+
+ var members = user.Members == null ? [] : user.Members.map(function (member) {
+ return (
+
+ {member.profileName} ({member.name})
+
+ )
+ })
+ return (
+
+
+
+
+
{user.profileName}
+
{user.name}
+
+
+
+
+
+
{members.length} {members.length > 0 ? 'Members' : 'Member'}
+
+
+
+
{userPlanets.length} {userPlanets.length > 0 ? 'Planets' : 'Planet'}
+
+
+
+ )
+ },
+ renderUserHome: function () {
+ var user = this.state.user
+
+ var userPlanets = user.Planets.map(function (planet) {
+ return (
+
+ {planet.userName}/{planet.name}
+ {!planet.public ? () : null}
+
+ )
+ })
+
+ var teams = user.Teams == null ? [] : user.Teams.map(function (team) {
+ return (
+
+ {team.profileName} ({team.name})
+
+ )
+ })
+
+ var teamPlanets = user.Teams == null ? [] : user.Teams.map(function (team) {
+ var planets = team.Planets.map(function (planet) {
+ return (
+
+ {planet.userName}/{planet.name}
+ {!planet.public ? () : null}
+
+ )
+ })
+ return (
+
+ )
+ })
+
+ return (
+
+
+
+
+
{user.profileName}
+
{user.name}
+
+
+
+
+
+
{teams.length} {teams.length > 0 ? 'Teams' : 'Team'}
+
+
+
+
{userPlanets.length} {userPlanets.length > 0 ? 'Planets' : 'Planet'}
+
+ {teamPlanets}
+
+
+ )
}
})
diff --git a/browser/main/Services/Hq.js b/browser/main/Services/Hq.js
index ae855c2e..42d775a0 100644
--- a/browser/main/Services/Hq.js
+++ b/browser/main/Services/Hq.js
@@ -44,6 +44,14 @@ module.exports = {
})
.send(input)
},
+ createTeam: function (userName, input) {
+ return request
+ .post(apiUrl + 'resources/' + userName + '/teams')
+ .set({
+ Authorization: 'Bearer ' + localStorage.getItem('token')
+ })
+ .send(input)
+ },
createPlanet: function (userName, input) {
return request
.post(apiUrl + 'resources/' + userName + '/planets')
diff --git a/browser/main/Stores/PlanetStore.js b/browser/main/Stores/PlanetStore.js
index 08cbd08a..08dcac47 100644
--- a/browser/main/Stores/PlanetStore.js
+++ b/browser/main/Stores/PlanetStore.js
@@ -2,35 +2,94 @@
var Reflux = require('reflux')
+var UserStore = require('./UserStore')
+
var actions = Reflux.createActions([
- 'updatePlanet',
- 'destroyPlanet',
+ 'update',
+ 'destroy',
'updateCode',
'destroyCode',
'updateNote',
'destroyNote'
])
+function deleteItemFromTargetArray (item, targetArray) {
+ targetArray.some(function (_item, index) {
+ if (_item.id === item.id) {
+ targetArray.splice(index, 1)
+ return true
+ }
+ return false
+ })
+
+ return targetArray
+}
+
+function updateItemToTargetArray (item, targetArray) {
+ var isNew = !targetArray.some(function (_item, index) {
+ if (_item.id === item.id) {
+ targetArray.splice(index, 1, item)
+ return true
+ }
+ return false
+ })
+
+ if (isNew) targetArray.push(item)
+
+ return targetArray
+}
+
module.exports = Reflux.createStore({
listenables: [actions],
Actions: actions,
- onUpdatePlanet: function (planet) {
+ onUpdate: function (planet) {
+ // Copy the planet object
+ var aPlanet = Object.assign({}, planet)
+ delete aPlanet.Codes
+ delete aPlanet.Notes
+ // Check if the planet should be updated to currentUser
+ var currentUser = JSON.parse(localStorage.getItem('currentUser'))
+
+ var ownedByCurrentUser = currentUser.id === aPlanet.OwnerId
+
+ if (ownedByCurrentUser) {
+ currentUser.Planets = updateItemToTargetArray(aPlanet, currentUser.Planets)
+ }
+
+ if (!ownedByCurrentUser) {
+ var team = null
+ currentUser.Teams.some(function (_team) {
+ if (_team.id === aPlanet.OwnerId) {
+ team = _team
+ return true
+ }
+ return
+ })
+
+ if (team) {
+ team.Planets = updateItemToTargetArray(aPlanet, team.Planets)
+ }
+ }
+
+ // Update currentUser
+ localStorage.setItem('currentUser', JSON.stringify(currentUser))
+ UserStore.Actions.update(currentUser)
+
+ // Update the planet
+ localStorage.setItem('planet-' + planet.id, JSON.stringify(planet))
+
+ this.trigger({
+ status: 'updated',
+ data: planet
+ })
},
onUpdateCode: function (code) {
code.type = 'code'
var planet = JSON.parse(localStorage.getItem('planet-' + code.PlanetId))
if (planet != null) {
- var isNew = !planet.Codes.some(function (_code, index) {
- if (code.id === _code.id) {
- planet.Codes.splice(index, 1, code)
- return true
- }
- return false
- })
-
- if (isNew) planet.Codes.unshift(code)
+ planet.Codes = updateItemToTargetArray(code, planet.Codes)
localStorage.setItem('planet-' + code.PlanetId, JSON.stringify(planet))
}
@@ -43,16 +102,11 @@ module.exports = Reflux.createStore({
onDestroyCode: function (code) {
var planet = JSON.parse(localStorage.getItem('planet-' + code.PlanetId))
if (planet != null) {
- planet.Codes.some(function (_code, index) {
- if (code.id === _code.id) {
- planet.Codes.splice(index, 1)
- return true
- }
- return false
- })
+ planet.Codes = deleteItemFromTargetArray(code, planet.Codes)
localStorage.setItem('planet-' + code.PlanetId, JSON.stringify(planet))
}
+ code.type = 'code'
this.trigger({
status: 'codeDestroyed',
@@ -64,15 +118,7 @@ module.exports = Reflux.createStore({
var planet = JSON.parse(localStorage.getItem('planet-' + note.PlanetId))
if (planet != null) {
- var isNew = !planet.Notes.some(function (_note, index) {
- if (note.id === _note.id) {
- planet.Notes.splice(index, 1, note)
- return true
- }
- return false
- })
-
- if (isNew) planet.Codes.unshift(note)
+ planet.Notes = updateItemToTargetArray(note, planet.Notes)
localStorage.setItem('planet-' + note.PlanetId, JSON.stringify(planet))
}
@@ -85,16 +131,11 @@ module.exports = Reflux.createStore({
onDestroyNote: function (note) {
var planet = JSON.parse(localStorage.getItem('planet-' + note.PlanetId))
if (planet != null) {
- planet.Notes.some(function (_note, index) {
- if (note.id === _note.id) {
- planet.Notes.splice(index, 1)
- return true
- }
- return false
- })
+ planet.Notes = deleteItemFromTargetArray(note, planet.Notes)
localStorage.setItem('planet-' + note.PlanetId, JSON.stringify(planet))
}
+ note.type = 'note'
this.trigger({
status: 'noteDestroyed',
diff --git a/browser/styles/main/containers/UserContainer.styl b/browser/styles/main/containers/UserContainer.styl
index 3b1647e1..733b8e25 100644
--- a/browser/styles/main/containers/UserContainer.styl
+++ b/browser/styles/main/containers/UserContainer.styl
@@ -194,16 +194,20 @@
margin-top 25px
padding 10px 15px
border-radius 5px
- .teamList
+ .teamList, .memberList
absolute left bottom
top 125px
width 200px
padding 15px
border-right solid 1px borderColor
overflow-y auto
- .teamLabel
+ .teamLabel, .memberLabel
font-size 1.2em
margin-bottom 15px
+ .teams, .members
+ li
+ margin-bottom 10px
+ font-size 1.1em
.planetList
absolute right bottom
top 125px
@@ -212,7 +216,7 @@
overflow-y auto
.planetLabel
font-size 1.2em
- margin-bottom 25px
+ margin-bottom 15px
.planetGroup
margin-left 15px
.planetGroupLabel
@@ -220,3 +224,5 @@
margin-bottom 15px
.planets
margin-left 15px
+ li
+ margin-bottom 10px
diff --git a/browser/styles/shared/modal.styl b/browser/styles/shared/modal.styl
index 99e8ad73..65a804f3 100644
--- a/browser/styles/shared/modal.styl
+++ b/browser/styles/shared/modal.styl
@@ -171,7 +171,7 @@
border-radius 5px
marked()
- .PlanetCreateModal.modal, .PlanetAddUserModal.modal
+ .PlanetCreateModal.modal, .TeamCreateModal.modal
padding 60px 0
.nameInput
width 80%