carte-server 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/carte.gemspec +1 -0
- data/lib/carte/client/helpers.coffee +4 -1
- data/lib/carte/client/models/card.coffee +2 -1
- data/lib/carte/client/views/content.cjsx +1 -1
- data/lib/carte/client/views/header.cjsx +3 -2
- data/lib/carte/client/views/list.cjsx +14 -18
- data/lib/carte/client/views/pagination.cjsx +3 -1
- data/lib/carte/server.rb +7 -4
- data/lib/carte/server/models/card.rb +8 -2
- data/lib/carte/server/tasks.rb +13 -0
- data/lib/carte/server/version.rb +1 -1
- data/package.json +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9924e7dfa9f1be40fac1767395cb53f4855c016
|
4
|
+
data.tar.gz: 79e9aaf3531ef5494142426b88ef6838a5886532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5845160a604995b0ea42460a4b34bb66d5fe0ef2203ba94c341046ea23cd78b31cd70a68b75feeec9dfbb9928e63b954843e9510ae147f9d973d6e28a47183e
|
7
|
+
data.tar.gz: a2c858d32f6fe6b28aae28fbe1e63e8d91ef643c813b7fc3d1f1bfaef3d9a9d3e7ace4b445937ef090c48c273ef92fb539555bdf76e5e9427876230a54675636
|
data/carte.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
Backbone = require('backbone')
|
2
2
|
config = require('../../shared/config.json')
|
3
|
+
querystring = require('querystring')
|
3
4
|
|
4
5
|
module.exports = class Card extends Backbone.Model
|
5
6
|
idAttribute: 'title'
|
@@ -14,7 +15,7 @@ module.exports = class Card extends Backbone.Model
|
|
14
15
|
url = '/api/cards.json'
|
15
16
|
else
|
16
17
|
console.log 'url is not new'
|
17
|
-
url = '/api/cards/' + @get('title') + '.json'
|
18
|
+
url = '/api/cards/' + encodeURIComponent(@get('title')) + '.json'
|
18
19
|
if config.api_path
|
19
20
|
url = config.api_path + url
|
20
21
|
url
|
@@ -37,7 +37,7 @@ module.exports = React.createClass
|
|
37
37
|
title = 'search: ' + cards.query.title + ' (' + title + ')' if cards.query.title
|
38
38
|
title += ' - ' + config.title
|
39
39
|
document.title = title
|
40
|
-
<List key='list' cards={cards} showNav=true />
|
40
|
+
<List key='list' router={@props.router} cards={cards} showNav=true />
|
41
41
|
when "show"
|
42
42
|
console.log 'show'
|
43
43
|
cards = new CardCollection()
|
@@ -4,6 +4,7 @@ React = require('react')
|
|
4
4
|
Edit = require('./edit')
|
5
5
|
CardModel = require('../models/card')
|
6
6
|
ModalTrigger = require('react-bootstrap/lib/ModalTrigger')
|
7
|
+
helpers = require('../helpers')
|
7
8
|
config = require('../../shared/config.json')
|
8
9
|
|
9
10
|
module.exports = React.createClass
|
@@ -36,10 +37,10 @@ module.exports = React.createClass
|
|
36
37
|
<nav className="navbar navbar-default" style={{padding:"0px",backgroundColor:"white",marginBottom:"5px"}}>
|
37
38
|
<div className="container-fluid">
|
38
39
|
<div className="navbar-header">
|
39
|
-
<a className="navbar-brand" href={if config.icon_link then config.icon_link else "#/"} style={{paddingTop:"10px"}}>
|
40
|
+
<a className="navbar-brand" onClick={helpers.reload} href={if config.icon_link then config.icon_link else "#/"} style={{paddingTop:"10px"}}>
|
40
41
|
<img alt="Brand" src="/images/icon.png" width="30" height="30" />
|
41
42
|
</a>
|
42
|
-
<a className="navbar-brand" href="#/">
|
43
|
+
<a className="navbar-brand" onClick={helpers.reload} href="#/">
|
43
44
|
{config.title}
|
44
45
|
</a>
|
45
46
|
</div>
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# @cjsx React.DOM
|
2
2
|
$ = require('jquery')
|
3
|
+
Backbone = require('backbone')
|
3
4
|
React = require('react')
|
4
5
|
Cards = require('./cards')
|
5
6
|
CardCollection = require('../models/cards')
|
@@ -17,27 +18,22 @@ module.exports = React.createClass
|
|
17
18
|
nextProps.cards.on 'sync', @forceUpdate.bind(@, null)
|
18
19
|
|
19
20
|
atozParam: ()->
|
20
|
-
|
21
|
-
query = $.extend query, {sort: 'title', order: 'asc', page: 1}
|
22
|
-
delete query.seed
|
23
|
-
$.param(query)
|
21
|
+
@queryParam {sort: 'title', order: 'asc', page: 1}, []
|
24
22
|
|
25
23
|
latestParam: ()->
|
26
|
-
|
27
|
-
query = $.extend query, {sort: 'updated_at', order: 'desc', page: 1}
|
28
|
-
delete query.seed
|
29
|
-
$.param(query)
|
24
|
+
@queryParam {sort: 'updated_at', order: 'desc', page: 1}, []
|
30
25
|
|
31
26
|
randomParam: ()->
|
32
|
-
|
33
|
-
query = $.extend query, {order: 'random', page: 1, seed: new Date().getTime()}
|
34
|
-
delete query.sort
|
35
|
-
delete query.page
|
36
|
-
$.param(query)
|
27
|
+
@queryParam {order: 'random'}, ['sort', 'page']
|
37
28
|
|
38
29
|
tagParam: (tag)->
|
30
|
+
@queryParam {tag: tag}, ['seed']
|
31
|
+
|
32
|
+
queryParam: (param, deleteKeys)->
|
39
33
|
query = $.extend {}, @props.cards.query
|
40
|
-
query = $.extend query,
|
34
|
+
query = $.extend query, param
|
35
|
+
for key in deleteKeys
|
36
|
+
delete query[key]
|
41
37
|
$.param(query)
|
42
38
|
|
43
39
|
render: ->
|
@@ -47,9 +43,9 @@ module.exports = React.createClass
|
|
47
43
|
<div className="row">
|
48
44
|
<div className="col-sm-6" style={{padding:"0px"}}>
|
49
45
|
<ul className="nav nav-pills">
|
50
|
-
<li><a href={"#/?" + @atozParam()} style={{padding:'6px 12px',fontWeight: if @props.cards.query.sort == 'title' and @props.cards.query.order != 'random' then 'bold' else 'normal'}}>A to Z</a></li>
|
51
|
-
<li><a href={"#/?" + @latestParam()} style={{padding:'6px 12px',fontWeight: if @props.cards.query.sort == 'updated_at' and @props.cards.query.order != 'random' then 'bold' else 'normal'}}>Latest</a></li>
|
52
|
-
<li><a href={"#/?" + @randomParam()} style={{padding:'6px 12px',fontWeight: if @props.cards.query.order == 'random' then 'bold' else 'normal'}}>Random</a></li>
|
46
|
+
<li><a onClick={helpers.reload} href={"#/?" + @atozParam()} style={{padding:'6px 12px',fontWeight: if @props.cards.query.sort == 'title' and @props.cards.query.order != 'random' then 'bold' else 'normal'}}>A to Z</a></li>
|
47
|
+
<li><a onClick={helpers.reload} href={"#/?" + @latestParam()} style={{padding:'6px 12px',fontWeight: if @props.cards.query.sort == 'updated_at' and @props.cards.query.order != 'random' then 'bold' else 'normal'}}>Latest</a></li>
|
48
|
+
<li><a onClick={helpers.reload} href={"#/?" + @randomParam()} style={{padding:'6px 12px',fontWeight: if @props.cards.query.order == 'random' then 'bold' else 'normal'}}>Random</a></li>
|
53
49
|
{
|
54
50
|
if @props.cards.query.tags
|
55
51
|
@props.cards.query.tags.split(',').map (tag)=>
|
@@ -64,7 +60,7 @@ module.exports = React.createClass
|
|
64
60
|
<li>
|
65
61
|
{
|
66
62
|
if @props.cards.page
|
67
|
-
<a href={"#/?" + @randomParam()} style={{padding:'6px 12px'}}>
|
63
|
+
<a onClick={helpers.reload} href={"#/?" + @randomParam()} style={{padding:'6px 12px'}}>
|
68
64
|
<i className="glyphicon glyphicon-refresh" />
|
69
65
|
</a>
|
70
66
|
else
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# @cjsx React.DOM
|
2
|
+
Backbone = require('backbone')
|
2
3
|
$ = require('jquery')
|
3
4
|
React = require('react')
|
5
|
+
helpers = require('../helpers')
|
4
6
|
|
5
7
|
module.exports = React.createClass
|
6
8
|
displayName: 'Pagination'
|
@@ -29,7 +31,7 @@ module.exports = React.createClass
|
|
29
31
|
<li style={width:'4.0em',textAlign:'center'}>
|
30
32
|
{
|
31
33
|
if @props.cards.page
|
32
|
-
<a href={"#/?" + @pageParam(@props.cards.page.current)} style={{padding:'6px 12px'}}>
|
34
|
+
<a href={"#/?" + @pageParam(@props.cards.page.current)} onClick={helpers.reload} style={{padding:'6px 12px'}}>
|
33
35
|
{@props.cards.page.current} / {@props.cards.page.total}
|
34
36
|
</a>
|
35
37
|
else
|
data/lib/carte/server.rb
CHANGED
@@ -4,6 +4,7 @@ require 'mongoid'
|
|
4
4
|
require 'mongoid_auto_increment_id'
|
5
5
|
require 'will_paginate_mongoid'
|
6
6
|
require 'mongoid-simple-tags'
|
7
|
+
require 'mongoid/geospatial'
|
7
8
|
require 'carte/server/validators'
|
8
9
|
require 'carte/server/models'
|
9
10
|
|
@@ -14,6 +15,7 @@ module Carte
|
|
14
15
|
include Carte::Server::Models
|
15
16
|
|
16
17
|
configure do
|
18
|
+
set :protection, :except => :path_traversal
|
17
19
|
set :views, File.join(File.dirname(__FILE__), 'server/views')
|
18
20
|
set :public_folder, 'public'
|
19
21
|
set :script_path, '/app.js'
|
@@ -29,18 +31,19 @@ module Carte
|
|
29
31
|
order = (params[:order] && %w(asc desc random).include?(params[:order])) ? params[:order] : 'desc'
|
30
32
|
sort = (params[:sort] && %w(title created_at updated_at).include?(params[:sort])) ? params[:sort] : 'updated_at'
|
31
33
|
if order == 'random'
|
32
|
-
|
34
|
+
cards = Card.random
|
35
|
+
else
|
36
|
+
cards = Card.send(order, sort)
|
33
37
|
end
|
34
|
-
cards = Card.send(order, sort)
|
35
38
|
if title = params[:title]
|
36
|
-
cards = cards.any_of({title: /#{title}/})
|
39
|
+
cards = cards.any_of({title: /#{title}/i})
|
37
40
|
end
|
38
41
|
if params[:tags]
|
39
42
|
tags = params[:tags].split(',')
|
40
43
|
cards = cards.tagged_with_all(tags)
|
41
44
|
end
|
42
45
|
if content = params[:content]
|
43
|
-
cards = cards.any_of({content: /#{content}/})
|
46
|
+
cards = cards.any_of({content: /#{content}/i})
|
44
47
|
end
|
45
48
|
cards = cards.paginate(per_page: 9, page: params[:page])
|
46
49
|
end
|
@@ -6,10 +6,12 @@ module Carte
|
|
6
6
|
include Mongoid::Timestamps
|
7
7
|
include Mongoid::Attributes::Dynamic
|
8
8
|
include Mongoid::Document::Taggable
|
9
|
+
include Mongoid::Geospatial
|
9
10
|
|
10
11
|
field :title, type: String
|
11
12
|
field :new_title, type: String
|
12
13
|
field :content, type: String
|
14
|
+
field :random_point, type: Point, spatial: true
|
13
15
|
|
14
16
|
index({title: 1}, {unique: true, name: "title_index"})
|
15
17
|
|
@@ -38,9 +40,13 @@ module Carte
|
|
38
40
|
self.new_title = nil
|
39
41
|
end
|
40
42
|
end
|
43
|
+
|
44
|
+
before_create do
|
45
|
+
self.random_point = [Random.rand, 0]
|
46
|
+
end
|
41
47
|
|
42
|
-
def self.
|
43
|
-
self.
|
48
|
+
def self.random
|
49
|
+
self.near(random_point: [Random.rand, 0])
|
44
50
|
end
|
45
51
|
|
46
52
|
def lefts(size=1)
|
data/lib/carte/server/tasks.rb
CHANGED
@@ -44,4 +44,17 @@ namespace :carte do
|
|
44
44
|
task :reset do
|
45
45
|
Card.delete_all
|
46
46
|
end
|
47
|
+
|
48
|
+
desc 'create indexes'
|
49
|
+
task :create_indexes do
|
50
|
+
Card.create_indexes
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'update random point'
|
54
|
+
task :update_random do
|
55
|
+
Card.all.each do |card|
|
56
|
+
card.random_point = [Random.rand, 0]
|
57
|
+
card.save!
|
58
|
+
end
|
59
|
+
end
|
47
60
|
end
|
data/lib/carte/server/version.rb
CHANGED
data/package.json
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carte-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tily
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - '>='
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: mongoid-geospatial
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - '>='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - '>='
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
195
209
|
description: something like dictionary, wiki, or information card
|
196
210
|
email:
|
197
211
|
- tidnlyam@gmail.com
|