Skip to content

Commit 27932fe

Browse files
committed
#5 Add index page with table
1 parent 94a0128 commit 27932fe

File tree

8 files changed

+63
-35
lines changed

8 files changed

+63
-35
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Place all the behaviors and hooks related to the matching controller here.
2+
// All this logic will automatically be available in application.js.
3+
4+
Dropzone.options.mediaDropzone = {
5+
paramName: "attachment",
6+
maxFilesize: 2,
7+
clickable: true,
8+
addRemoveLinks: true,
9+
init: function () {
10+
return this.on('removedfile', function(file) {
11+
if (file.xhr) {
12+
return $.ajax({
13+
url: "" + ($("#media-dropzone").attr("action")) + "/" + (JSON.parse(file.xhr.response).id),
14+
type: 'DELETE'
15+
});
16+
}
17+
});
18+
}
19+
};

app/assets/javascripts/kebapage/photos.js

-2
This file was deleted.

app/controllers/kebapage/media_controller.rb

+6-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
module Kebapage
44
class MediaController < ApplicationController
5+
6+
def index
7+
@media = Medium.all
8+
@medium = Medium.new
9+
end
10+
511
def create
612
@medium = Medium.create(attachment: params[:attachment ])
7-
puts #{params[:attachment]}
813
render json: @media
914
end
1015

@@ -13,14 +18,5 @@ def destroy
1318
@medium.destroy
1419
render nothing: true
1520
end
16-
17-
def photos
18-
@uploads = Medium.all
19-
20-
respond_to do |format|
21-
format.json { render json: @uploads }
22-
format.js
23-
end
24-
end
2521
end
2622
end
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=stylesheet_link_tag 'kebapage/application'
2+
3+
.form-group
4+
=form_for @medium, multipart: true, html: { class: :dropzone, id: 'media-dropzone' } do |f|
5+
=f.hidden_field :attachment
6+
7+
.panel.panel-default.grid
8+
.panel-heading
9+
%i.icon-table.icon-large
10+
Media Manager Index Page
11+
12+
%table.table
13+
%thead
14+
%tr
15+
%th #
16+
%th Filetype
17+
%th File size
18+
%th Upload date
19+
%th.actions
20+
Actions
21+
22+
%t.body.success
23+
- @media.each do |media|
24+
%tr
25+
%td
26+
= (@media.index media) + 1
27+
%td
28+
= media.attachment_content_type
29+
%td
30+
= media.attachment_file_size.to_i / 1024
31+
%td
32+
= media.attachment_updated_at
33+
%td.action
34+
%a.btn.btn-success{href: '#'}
35+
%i.icon-zoom-in
36+
37+
=javascript_include_tag 'kebapage/application'

app/views/kebapage/media/photos.js.erb

-3
This file was deleted.

app/views/kebapage/static_pages/_form.html.haml

-17
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,3 @@
2323
=f.hidden_field :attachment
2424

2525
=javascript_include_tag "kebapage/application"
26-
:javascript
27-
Dropzone.options.photoDropzone = {
28-
paramName: "attachment",
29-
maxFilesize: 2,
30-
clickable: true,
31-
addRemoveLinks: true,
32-
init: function () {
33-
return this.on('removedfile', function(file) {
34-
if (file.xhr) {
35-
return $.ajax({
36-
url: "" + ($("#media-dropzone").attr("action")) + "/" + (JSON.parse(file.xhr.response).id),
37-
type: 'DELETE'
38-
});
39-
}
40-
});
41-
}
42-
};

config/routes.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
Kebapage::Engine.routes.draw do
2-
resources :media, only: [:create, :destroy, :photos] do
3-
get :media, on: :collection
4-
end
2+
resources :media, only: [:index, :create, :destroy]
53
resources :static_pages, except: [:show]
64
root 'static_pages#index'
75
end

0 commit comments

Comments
 (0)