tomify 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ad48b3ce738012cd5586f14612a7c57517bde4d
4
- data.tar.gz: 1fc96ad471a7221bfdebc6940b09dad8f628d5c1
3
+ metadata.gz: 34bf7184118f201d83d1ef89b98057bb1d41f53e
4
+ data.tar.gz: ac949b2ec8b51179601e9ee09ae94902d41c590d
5
5
  SHA512:
6
- metadata.gz: 71950755f898ab68dc1eb8254c872ebf9ca23241b50dfce9e236bac9985802142dc0db297cb0e70e752613f73e1356a2917527a379c9ff0387cb731268c6fdbe
7
- data.tar.gz: cc9a1edaefeaf2fb3091de2269d2de8d146e6a84ef212898e2663af1a834316db39c0e8caeeeb0b79bd9bf17bf003b9fa6ed6b884bc69b23320388379a904735
6
+ metadata.gz: 3638b5741f85d2218f22ffcf61b52d4a211c2140e9e0623d3c104af6fcb780b4a4b8f0161678d227b3745bffece49b36c4a9eaf47efb0a9cd48f09fffdc212ea
7
+ data.tar.gz: c2c8fb0eb2a8dfc5046aa1f74fefa24bf3b2ecfc52027fb9083656c4257fb8f709dfdc1367fe2822f5ce964ed268d0701e117d0d857713fce7ef01fdb9ce5d44
@@ -25,7 +25,9 @@ $ ->
25
25
  Store.find("Params").set params
26
26
  Store.find("Env").set window.env
27
27
 
28
- @message = (message) -> Store.find("Messages").push message
28
+ @message = (message) =>
29
+ message.id ?= @uuid()
30
+ Store.find("Messages").push message
29
31
  @redirect = (path) -> location.assign path || "/"
30
32
  @setting = (name) ->
31
33
  setting = Store.find("Settings").get().find (setting) -> setting.name == name
@@ -35,3 +37,4 @@ $ ->
35
37
  page ?= { path: path ? template }
36
38
  if page.root then "/" else "/#{page.path}"
37
39
  @addPlugin = (plugin) -> Store.find("Plugins").push plugin
40
+ @uuid = -> Math.random().toString(36).substr(2, 9)
@@ -2,9 +2,12 @@ Component.create "Layout.Messages",
2
2
  followStores: ["messages"]
3
3
  componentWillInitialize: ->
4
4
  @store = Store.create "Messages", window.env.messages
5
- @follow @store.on "push", -> $("body").scrollTop(0)
5
+ @follow @store.on "push", (message) =>
6
+ $("body").scrollTop(0)
7
+ setTimeout @remove.bind(null, message), 5000
6
8
  remove: (i, e) ->
7
- e.preventDefault()
9
+ e && e.preventDefault()
10
+ i = @store.get().map((m) -> m.id).indexOf(i.id) if i?.id
8
11
  @store.remove(i)
9
12
  false
10
13
  render: ->
@@ -31,7 +31,7 @@ Component.create "Layout.PublicNavbar",
31
31
  if @state.user.id
32
32
  @link(name: "Profile", url: "/profile")
33
33
  else
34
- @link(name: "Login", url: "/session")
34
+ @link(name: setting("login_text") || "Login", url: "/session")
35
35
  }
36
36
  {for page in @state.pages
37
37
  if page.children[0]
@@ -1,29 +1,38 @@
1
- Model.create "Public.Subscription", path: "subscription"
2
-
3
1
  Component.create "Public.Subscription",
4
- getInitialState: -> { email: Store.find("Params").get("email") }
2
+ getInitialState: -> { subscription: { active: true, email: Store.find("Params").get("email") }}
5
3
  componentWillInitialize: ->
6
- @model = Model.find "Public.Subscription"
4
+ @model = Model.findOrCreate "Public.Subscription"
7
5
  @store = Store.findOrCreate "Public.Subscription"
8
- @follow @model.on "destroy", @modelDestroy
9
- modelDestroy: (response) ->
10
- message type: response.type, text: response.message unless response.type == "success"
11
- @setState unsubscribed: true, message: response.message
6
+ @follow @model.on "edit", @modelUpdate
7
+ @follow @model.on "create", @modelUpdate
8
+ @follow @model.on "destroy", @modelUpdate
9
+ @model.edit(Store.find("Params").get "email")
10
+ modelUpdate: (response) ->
11
+ message type: response.type, text: response.message if response.message
12
+ @setState subscription: response.data if response.data
13
+ create: (e) ->
14
+ e.preventDefault()
15
+ @model.create email: @state.subscription.email
12
16
  destroy: (e) ->
13
17
  e.preventDefault()
14
- @model.destroy subscription: { email: @state.email }
18
+ @model.destroy email: @state.subscription.email
15
19
  render: ->
16
20
  <div className="row text-center">
17
21
  <div className="dynamic-sm">
18
- <h3>Unsubscribe</h3>
19
- {if @state.unsubscribed
20
- <p>{@state.message}</p>
22
+ <h3>Subscription</h3>
23
+ {if @state.subscription.active
24
+ <div>
25
+ <p>
26
+ <strong>{@state.subscription.email}</strong> will be no longer recieve the majority of emails from {setting "name"}.
27
+ </p>
28
+ <a href="#" onClick={@destroy} className="btn btn-danger" data-confirm="Are you sure?">Unsubscribe</a>
29
+ </div>
21
30
  else
22
31
  <div>
23
32
  <p>
24
- By clicking Submit, <strong>{@state.email}</strong> will be no longer recieve the majority of emails from {setting "name"}.
33
+ <strong>{@state.subscription.email}</strong> will be subscribed to the emails from {setting "name"}.
25
34
  </p>
26
- <a href="#" onClick={@destroy} className="btn btn-danger" data-confirm="Are you sure?">Submit</a>
35
+ <a href="#" onClick={@create} className="btn btn-primary">Subscribe</a>
27
36
  </div>
28
37
  }
29
38
  </div>
@@ -48,7 +48,9 @@ Component.create "Public.Users.Edit",
48
48
  </div>
49
49
  <div className="form-group">
50
50
  <small>
51
- <a href="#" onClick={@destroy} data-confirm="Are you sure you want to permanently delete your account?">Delete</a>
51
+ <a href="#{path 'subscription'}?email=#{@form.record.get 'email'}">Email Subscription</a>
52
+ <span> | </span>
53
+ <a href="#" onClick={@destroy} data-confirm="Are you sure you want to permanently delete your account?">Delete Account</a>
52
54
  </small>
53
55
  </div>
54
56
  </form>
@@ -1,11 +1,24 @@
1
1
  class Tomify::Api::Public::SubscriptionsController < Tomify.controllers.public_api
2
+ def create
3
+ record.activities.create(action: action_name, controller: controller_name)
4
+ if record.update(active: true)
5
+ render json: { type: :success, data: data, message: "You have been subscribed to #{setting(:name)}" }
6
+ else
7
+ render json: { type: :warning, message: "There was a problem subscribing you to #{setting(:name)}" }
8
+ end
9
+ end
10
+
2
11
  def destroy
3
- subscription = Tomify.models.subscription.find_or_create_by(email: params[:subscription][:email])
4
- subscription.activities.create(action: action_name, controller: controller_name)
5
- if subscription.update(active: false)
6
- render json: { type: :success, message: "You have been unsubscribed from #{setting(:name)}" }
12
+ record.activities.create(action: action_name, controller: controller_name)
13
+ if record.update(active: false)
14
+ render json: { type: :success, data: data, message: "You have been unsubscribed from #{setting(:name)}" }
7
15
  else
8
16
  render json: { type: :warning, message: "There was a problem unsubscribing you from #{setting(:name)}" }
9
17
  end
10
18
  end
19
+
20
+ private
21
+ def find_record
22
+ @record ||= Tomify.models.subscription.find_or_create_by(email: params[:email] || params[:subscription][:email])
23
+ end
11
24
  end
@@ -41,11 +41,11 @@ module Tomify::Concerns::Api::Helpers
41
41
  end
42
42
 
43
43
  def record
44
- @record
44
+ @record ||= find_record
45
45
  end
46
46
 
47
47
  def records
48
- @records
48
+ @records ||= find_records
49
49
  end
50
50
 
51
51
  def record_params
@@ -33,19 +33,17 @@ module Tomify::Concerns::Api::JSON
33
33
  end
34
34
 
35
35
  def update
36
- find_record
37
36
  update_record
38
37
  render json: { type: :success, data: data, message: "#{model_name} Updated" }
39
38
  end
40
39
 
41
40
  def destroy
42
- find_record
43
41
  destroy_record
44
42
  render json: { type: :danger, message: "#{model_name} Deleted" }
45
43
  end
46
44
 
47
45
  private
48
46
  def data
49
- @data ||= (record || records).as_json(serializable_options)
47
+ @data ||= (@record || @records).as_json(serializable_options)
50
48
  end
51
49
  end
@@ -50,7 +50,7 @@ module Tomify::Concerns::Default::NavbarHelper
50
50
  def navbar_pages_from(item)
51
51
  case item
52
52
  when Proc
53
- navbar_pages_from item.call
53
+ navbar_pages_from item.call(self)
54
54
  when Hash
55
55
  navbar_pages_from_hash item
56
56
  when Array
data/config/routes.rb CHANGED
@@ -34,7 +34,8 @@ Rails.application.routes.draw do
34
34
  resource :user, only: [:create, :show, :update, :destroy]
35
35
  resource :session, only: [:create, :destroy]
36
36
  resource :password, only: :create
37
- resource :subscription, only: :destroy
37
+ resource :subscriptions, only: [:create, :destroy]
38
+ resources :subscriptions, only: :show, param: :email, constraints: { email: /[^\/]+/ }
38
39
  end
39
40
  end
40
41
 
@@ -1,3 +1,3 @@
1
1
  module Tomify
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Prats
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-05 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails