mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-22 14:11:42 +00:00
blueprint articles are available in planet list
This commit is contained in:
@@ -4,16 +4,21 @@ var request = require('superagent')
|
||||
|
||||
var PlanetActions = require('../Actions/PlanetActions')
|
||||
|
||||
var apiUrl = 'http://localhost:8000/'
|
||||
|
||||
var PlanetStore = Reflux.createStore({
|
||||
init: function () {
|
||||
this.listenTo(PlanetActions.fetchPlanet, this.fetchPlanet)
|
||||
this.listenTo(PlanetActions.createSnippet, this.createSnippet)
|
||||
this.listenTo(PlanetActions.updateSnippet, this.updateSnippet)
|
||||
this.listenTo(PlanetActions.deleteSnippet, this.deleteSnippet)
|
||||
this.listenTo(PlanetActions.createBlueprint, this.createBlueprint)
|
||||
this.listenTo(PlanetActions.updateBlueprint, this.updateBlueprint)
|
||||
this.listenTo(PlanetActions.deleteBlueprint, this.deleteBlueprint)
|
||||
},
|
||||
fetchPlanet: function (planetName) {
|
||||
request
|
||||
.get('http://localhost:8000/' + planetName)
|
||||
.get(apiUrl + planetName)
|
||||
.send()
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
@@ -23,7 +28,17 @@ var PlanetStore = Reflux.createStore({
|
||||
}
|
||||
|
||||
var planet = res.body
|
||||
planet.Snippets = planet.Snippets.sort(function (a, b) {
|
||||
planet.Snippets = planet.Snippets.map(function (snippet) {
|
||||
snippet.type = 'snippet'
|
||||
return snippet
|
||||
})
|
||||
|
||||
planet.Blueprints = planet.Blueprints.map(function (blueprint) {
|
||||
blueprint.type = 'blueprint'
|
||||
return blueprint
|
||||
})
|
||||
|
||||
planet.Articles = planet.Snippets.concat(planet.Blueprints).sort(function (a, b) {
|
||||
a = new Date(a.updatedAt)
|
||||
b = new Date(b.updatedAt)
|
||||
return a < b ? 1 : a > b ? -1 : 0
|
||||
@@ -38,13 +53,12 @@ var PlanetStore = Reflux.createStore({
|
||||
createSnippet: function (planetName, input) {
|
||||
input.description = input.description.substring(0, 255)
|
||||
request
|
||||
.post('http://localhost:8000/' + planetName + '/snippets')
|
||||
.post(apiUrl + planetName + '/snippets')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + localStorage.getItem('token')
|
||||
})
|
||||
.send(input)
|
||||
.end(function (req, res) {
|
||||
console.log('snippet created', res.body)
|
||||
this.trigger({
|
||||
status: 'snippetCreated',
|
||||
data: res.body
|
||||
@@ -54,7 +68,7 @@ var PlanetStore = Reflux.createStore({
|
||||
updateSnippet: function (id, input) {
|
||||
input.description = input.description.substring(0, 255)
|
||||
request
|
||||
.put('http://localhost:8000/snippets/id/' + id)
|
||||
.put(apiUrl + 'snippets/id/' + id)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + localStorage.getItem('token')
|
||||
})
|
||||
@@ -75,7 +89,7 @@ var PlanetStore = Reflux.createStore({
|
||||
},
|
||||
deleteSnippet: function (id) {
|
||||
request
|
||||
.del('http://localhost:8000/snippets/id/' + id)
|
||||
.del(apiUrl + 'snippets/id/' + id)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + localStorage.getItem('token')
|
||||
})
|
||||
@@ -93,6 +107,64 @@ var PlanetStore = Reflux.createStore({
|
||||
data: snippet
|
||||
})
|
||||
}.bind(this))
|
||||
},
|
||||
createBlueprint: function (planetName, input) {
|
||||
input.title = input.title.substring(0, 255)
|
||||
request
|
||||
.post(apiUrl + planetName + '/blueprints')
|
||||
.set({
|
||||
Authorization: 'Bearer ' + localStorage.getItem('token')
|
||||
})
|
||||
.send(input)
|
||||
.end(function (req, res) {
|
||||
this.trigger({
|
||||
status: 'blueprintCreated',
|
||||
data: res.body
|
||||
})
|
||||
}.bind(this))
|
||||
},
|
||||
updateBlueprint: function (id, input) {
|
||||
input.description = input.description.substring(0, 255)
|
||||
request
|
||||
.put(apiUrl + 'blueprints/id/' + id)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + localStorage.getItem('token')
|
||||
})
|
||||
.send(input)
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
this.trigger(null)
|
||||
return
|
||||
}
|
||||
|
||||
var blueprint = res.body
|
||||
this.trigger({
|
||||
status: 'blueprintUpdated',
|
||||
data: blueprint
|
||||
})
|
||||
}.bind(this))
|
||||
},
|
||||
deleteBlueprint: function (id) {
|
||||
request
|
||||
.del(apiUrl + 'blueprints/id/' + id)
|
||||
.set({
|
||||
Authorization: 'Bearer ' + localStorage.getItem('token')
|
||||
})
|
||||
.send()
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
this.trigger(null)
|
||||
return
|
||||
}
|
||||
|
||||
var blueprint = res.body
|
||||
this.trigger({
|
||||
status: 'blueprintDeleted',
|
||||
data: blueprint
|
||||
})
|
||||
}.bind(this))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user