tawork 0.0.5 → 0.0.6

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: ac26a56c3c8cd474334a1d3d3d731a636da0ce72
4
- data.tar.gz: 6a2d3dd9c84b343a819b0ca9f5d0c18cff4005f4
3
+ metadata.gz: d7e69c8a32ba03f38b1cfe381b6819223aa1c489
4
+ data.tar.gz: 7a9e007c0137f1277c98910c46303bc6d88eab2f
5
5
  SHA512:
6
- metadata.gz: af5aae6d26f7b45526cc571e95c6c001f5082086d602352545a11178585927cdf86c3353d44d1cf52417fd972cf546de9a46315893d149f5a5681b821d6a3fe3
7
- data.tar.gz: 3b498268218302122996324a45e97b8fecf104086cb0f5351de11b34fe796fe90a6c78c8de9332ed294f982438c7438d947e9b981857922df119ef88cea996ef
6
+ metadata.gz: f871d2e3d9f1af34682c575fba7c4b2cd6776fc7b5dd213bac57661f8db09ad1a0810554401ac5bf87f8b753880d8ab1ab4574d1a3e739145163d2efc6b0ece6
7
+ data.tar.gz: e4e00c364918dc52dded5a534debacff44c5fa27a7d7ced52cc61d4350b87db27328fb341f3f2f0b47c9c93d8abbd1cbabdf6410a878753b86f04ddc36e02210
@@ -0,0 +1,59 @@
1
+ class Tawork.Views.AttachmentView extends Backbone.View
2
+ events:
3
+ 'click .delete': 'delete_attachment'
4
+
5
+ initialize: (options = {}) ->
6
+ @attachment_id = @$el.data("attachment-id")
7
+ @setup_uploader()
8
+
9
+ delete_attachment: ->
10
+ self = this
11
+ if confirm("Are you sure you want to delete this file?")
12
+ $.ajax
13
+ method: "DELETE"
14
+ url: "/attachments/#{@attachment_id}"
15
+ success: (data) ->
16
+ self.remove()
17
+ false
18
+
19
+ setup_uploader: ->
20
+ uploader = new plupload.Uploader(
21
+ runtimes: "html5"
22
+ browse_button: "upload_attachment_#{@attachment_id}" # you can pass in id...
23
+ container: document.getElementById("attachments") # ... or DOM Element itself
24
+ url: "/attachments/#{@attachment_id}/upload"
25
+ filters:
26
+ max_file_size: "50mb"
27
+ multipart_params:
28
+ authenticity_token: $("meta[name=csrf-token]").attr('content')
29
+
30
+ init:
31
+ PostInit: ->
32
+ $("#filelist").html("")
33
+ # document.getElementById("uploadfiles").onclick = ->
34
+ # uploader.start()
35
+ # false
36
+
37
+ FilesAdded: (up, files) ->
38
+ plupload.each files, (file) ->
39
+ $template = $($("#upload_template").clone().html())
40
+ $template.attr("id", file.id).find(".filename").text(file.name + "(#{plupload.formatSize(file.size)})")
41
+ $("#filelist").append $template
42
+ uploader.start()
43
+
44
+
45
+ UploadProgress: (up, file) ->
46
+ $("##{file.id}").find(".bar").css(width: "#{file.percent}%")
47
+
48
+ FileUploaded: (up, file, response) ->
49
+ try
50
+ $("##{file.id}").fadeOut complete: ->
51
+ eval response.response
52
+ catch err
53
+ console.log err
54
+
55
+ Error: (up, err) ->
56
+ document.getElementById("console").innerHTML += "\nError #" + err.code + ": " + err.message
57
+ )
58
+
59
+ uploader.init()
@@ -229,3 +229,7 @@ li.mjs-nestedSortable-expanded
229
229
 
230
230
  h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6
231
231
  font-family: "Bitter", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif
232
+
233
+ .attachment
234
+ .actions a
235
+ margin-right: .5em
@@ -7,4 +7,16 @@ class AttachmentsController < ApplicationController
7
7
  filename: attachment.filename,
8
8
  disposition: 'inline'
9
9
  end
10
+
11
+ def upload
12
+ @attachment = Attachment.find params[:id]
13
+ @attachment.update(params[:file], current_user)
14
+ end
15
+
16
+ def destroy
17
+ @attachment = Attachment.find params[:id]
18
+ @attachment.destroy
19
+
20
+ render json: {}
21
+ end
10
22
  end
@@ -24,9 +24,7 @@ class Wiki::PagesController < ApplicationController
24
24
  def show
25
25
  @space = @page.root
26
26
  @subtree = @page.subtree.group_by(&:parent_id)
27
- @last_updated = @page.activities.
28
- where(key: 'page.update_details').
29
- order("created_at desc").first
27
+ @last_updated = @page.last_updated
30
28
  end
31
29
 
32
30
  def history
@@ -45,7 +43,12 @@ class Wiki::PagesController < ApplicationController
45
43
  if params[:markdown_body].present?
46
44
  update_params[:body] = redcarpet(params[:markdown_body])
47
45
  end
48
- if @page.update_attributes(update_params)
46
+
47
+ if @page.last_updated.created_at != Time.parse(params[:timestamp])
48
+ @page.errors.add(:base, "This page was edited by someone. Please refresh.")
49
+ end
50
+
51
+ if @page.errors.none? && @page.update_attributes(update_params)
49
52
  @page.update_to_gollum(current_user)
50
53
  @last_updated = @page.create_activity key: "page.update_details", owner: current_user
51
54
  end
@@ -79,7 +82,7 @@ class Wiki::PagesController < ApplicationController
79
82
  @attachment = Attachment.create_from_uploaded_file(params[:file], current_user, attachable: @page)
80
83
 
81
84
  if @attachment.errors.none?
82
- @activity = @ticket.page key: "ticket.attachment",
85
+ @activity = @page.create_activity key: "page.attachment",
83
86
  owner: current_user, recipient: @attachment
84
87
  end
85
88
  end
@@ -24,9 +24,34 @@ class Attachment < ActiveRecord::Base
24
24
  attachment
25
25
  end
26
26
 
27
+ def update(file, user)
28
+ filename = file.original_filename
29
+ if update_attributes(
30
+ filename: filename,
31
+ content_type: file.content_type,
32
+ size: file.size)
33
+
34
+ save_to_gollum(
35
+ file, user,
36
+ "uploading file: #{filename}"
37
+ )
38
+ end
39
+ end
40
+
41
+ def wiki_file
42
+ $wiki.file(wiki_page.path)
43
+ end
44
+
27
45
  def file_data
28
- format = File.extname(filename).gsub(".", "")
29
- $wiki.file(wiki_dir + "/" + wiki_attachment_data + "." + format).raw_data
46
+ wiki_file.raw_data
47
+ end
48
+
49
+ def wiki_page
50
+ $wiki.page(wiki_attachment_data, nil, wiki_dir)
51
+ end
52
+
53
+ def versions
54
+ wiki_page.versions
30
55
  end
31
56
 
32
57
  def save_to_gollum(file, user, message)
@@ -36,10 +61,12 @@ class Attachment < ActiveRecord::Base
36
61
  email: user.email
37
62
  }
38
63
 
39
- file_name = file.try(:original_filename) || File.basename(file.path)
40
- extension = File.extname(file_name).gsub(".", "")
41
64
  data_file = file.try(:tempfile) || file
42
- $wiki.write_page(wiki_attachment_data, extension, data_file, commit, wiki_dir)
65
+ if wiki_page.present?
66
+ $wiki.update_page(wiki_page, wiki_page.name, wiki_page.format, data_file, commit)
67
+ else
68
+ $wiki.write_page(wiki_attachment_data, :textile, data_file, commit, wiki_dir)
69
+ end
43
70
  end
44
71
 
45
72
  protected
@@ -49,6 +76,6 @@ class Attachment < ActiveRecord::Base
49
76
  end
50
77
 
51
78
  def wiki_dir
52
- "attachments/#{id}"
79
+ "/attachments/#{id}"
53
80
  end
54
81
  end
data/app/models/page.rb CHANGED
@@ -23,7 +23,7 @@ class Page < ActiveRecord::Base
23
23
  end
24
24
 
25
25
  def wiki_dir
26
- "wiki/#{id}"
26
+ "/wiki/#{id}"
27
27
  end
28
28
 
29
29
  def update_to_gollum(user)
@@ -36,14 +36,20 @@ class Page < ActiveRecord::Base
36
36
  body_page = "#{id}-body"
37
37
  title_page = "#{id}-title"
38
38
 
39
- $wiki.write_page(wiki_dir + "/" + body_page, :textile, body, commit)
40
- $wiki.write_page(wiki_dir + "/" + title_page, :textile, title, commit)
39
+ $wiki.write_page("/" + body_page, :textile, body, commit, wiki_dir)
40
+ $wiki.write_page("/" + title_page, :textile, title, commit, wiki_dir)
41
41
  end
42
42
 
43
43
  def type
44
44
  @type || "Page"
45
45
  end
46
46
 
47
+ def last_updated
48
+ activities.
49
+ where(key: 'page.update_details').
50
+ order("created_at desc").first
51
+ end
52
+
47
53
  def versions
48
54
  $wiki.page("#{id}-body", nil, wiki_dir).try(:versions) || []
49
55
  end
@@ -0,0 +1,2 @@
1
+ $(".attachment[data-attachment-id=<%= @attachment.id %>]").replaceWith('<%=j render '/wiki/pages/attachment', attachment: @attachment %>')
2
+
@@ -1,5 +1,12 @@
1
- %tr.attachment
1
+ %tr.attachment{data: {attachment_id: attachment.id}}
2
2
  %td.filename= link_to attachment.filename, attachment_path(attachment)
3
3
  %td.size= number_to_human_size(attachment.size)
4
- %td.versions 1
4
+ %td.versions= attachment.versions.count
5
5
  %td.actions
6
+ %a.upload{href: "#", title: "Upload", id: "upload_attachment_#{attachment.id}"}
7
+ %i.fa.fa-upload
8
+ %a.delete{href: "#", title: "Delete"}
9
+ %i.fa.fa-times
10
+ :coffeescript
11
+ $ ->
12
+ view = new Tawork.Views.AttachmentView el: $(".attachment[data-attachment-id=#{attachment.id}]").get(0)
@@ -129,17 +129,13 @@
129
129
  type: $(this).data("type")
130
130
  url: $(this).data("url")
131
131
  success: ->
132
- $(".edit-helper").toggleClass("hide")
133
- $(".save").hide()
134
- $(".edit").show()
135
- tinyMCE.remove('div');
136
132
 
137
133
  data:
134
+ timestamp: $(".time").data("timestamp")
138
135
  markdown_body: markdown_body
139
136
  type: #{@page.type.parameterize.to_json}
140
137
  parent_id: #{params[:parent_id].to_json}
141
138
  #{@page.type.parameterize}:
142
139
  title: title
143
140
  body: body
144
-
145
141
  false
@@ -3,4 +3,4 @@
3
3
  %span Last updated by
4
4
  .user= @last_updated.owner.display_name
5
5
  \-
6
- .time= timeago_tag @last_updated.created_at, date_only: false
6
+ .time{data: {timestamp: @last_updated.created_at}}= timeago_tag @last_updated.created_at, date_only: false
@@ -1,7 +1,11 @@
1
1
  <% if @page.errors.any? %>
2
- alert <%=raw @ticket.errors.to_a.to_json %>
2
+ alert <%=raw @page.errors.full_messages.to_json %>
3
3
  <% else %>
4
4
  $(".page_<%= @page.id %> .last-updated")
5
5
  .replaceWith('<%=j render 'last_updated' %>')
6
6
  $(".page_<%= @page.id %> .last-updated time").timeago()
7
+ $(".edit-helper").toggleClass("hide")
8
+ $(".save").hide()
9
+ $(".edit").show()
10
+ tinyMCE.remove('div');
7
11
  <% end %>
data/config/routes.rb CHANGED
@@ -27,7 +27,11 @@ Rails.application.class.routes.draw do
27
27
  end
28
28
  end
29
29
 
30
- resources :attachments, only: [:show]
30
+ resources :attachments, only: [:show, :destroy] do
31
+ member do
32
+ post :upload
33
+ end
34
+ end
31
35
  resources :projects
32
36
 
33
37
  resources :tickets do
@@ -1,3 +1,3 @@
1
1
  module Tawork
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tawork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adnan Ali
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -49,6 +49,7 @@ files:
49
49
  - app/assets/javascripts/backbone/tawork.js.coffee
50
50
  - app/assets/javascripts/backbone/templates/.gitkeep
51
51
  - app/assets/javascripts/backbone/views/.gitkeep
52
+ - app/assets/javascripts/backbone/views/attachment.js.coffee
52
53
  - app/assets/javascripts/backbone/views/page.js.coffee
53
54
  - app/assets/javascripts/backbone/views/ticket.js.coffee
54
55
  - app/assets/javascripts/backbone/views/tree_node_page.js.coffee
@@ -90,6 +91,7 @@ files:
90
91
  - app/models/ticket.rb
91
92
  - app/models/user.rb
92
93
  - app/models/user_verifier.rb
94
+ - app/views/attachments/upload.js.coffee
93
95
  - app/views/comments/_comment.html.haml
94
96
  - app/views/comments/_form.html.haml
95
97
  - app/views/comments/create.js.coffee