Add admin interface for the links
This commit is contained in:
parent
7657b05787
commit
1053b3883d
11 changed files with 142 additions and 0 deletions
49
plugins/links/app/controllers/admin/links_controller.rb
Normal file
49
plugins/links/app/controllers/admin/links_controller.rb
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
class Admin::LinksController < Admin::BaseController
|
||||||
|
def index
|
||||||
|
@links = Link.ordered
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@link = Link.new
|
||||||
|
render action: :edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@link = Link.new(link_params)
|
||||||
|
if @link.save
|
||||||
|
index
|
||||||
|
render action: :update_links
|
||||||
|
else
|
||||||
|
render action: :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@link = Link.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@link = Link.find(params[:id])
|
||||||
|
|
||||||
|
if @link.update_attributes!(link_params)
|
||||||
|
index
|
||||||
|
render action: :update_links
|
||||||
|
else
|
||||||
|
render action: :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
link = Link.find(params[:id])
|
||||||
|
link.destroy!
|
||||||
|
redirect_to admin_links_path
|
||||||
|
rescue => error
|
||||||
|
redirect_to admin_links_path, I18n.t('errors.general_msg', msg: error.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def link_params
|
||||||
|
params.require(:link).permit(:name, :url, :workgroup_id, :indirect, :authorization)
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,7 @@
|
||||||
class Link < ApplicationRecord
|
class Link < ApplicationRecord
|
||||||
belongs_to :workgroup
|
belongs_to :workgroup
|
||||||
|
|
||||||
|
validates_presence_of :name, :url
|
||||||
|
|
||||||
scope :ordered, -> { order(:name) }
|
scope :ordered, -> { order(:name) }
|
||||||
end
|
end
|
||||||
|
|
15
plugins/links/app/views/admin/links/_form.html.haml
Normal file
15
plugins/links/app/views/admin/links/_form.html.haml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
= simple_form_for [:admin, @link], validate: true, remote: true do |f|
|
||||||
|
.modal-header
|
||||||
|
= close_button :modal
|
||||||
|
%h3= @link.new_record? ? t('.title_new') : t('.title_edit')
|
||||||
|
.modal-body
|
||||||
|
= f.input :name
|
||||||
|
= f.input :url
|
||||||
|
= f.association :workgroup
|
||||||
|
= f.input :indirect, input_html: { 'data-toggle' => 'collapse', 'data-target' => '#authorization' }
|
||||||
|
#authorization{class: @link.indirect? ? '' : 'collapse'}
|
||||||
|
= f.input :authorization
|
||||||
|
%small= t '.description'
|
||||||
|
.modal-footer
|
||||||
|
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
||||||
|
= f.submit class: 'btn btn-primary'
|
15
plugins/links/app/views/admin/links/_links.html.haml
Normal file
15
plugins/links/app/views/admin/links/_links.html.haml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
%table.table.table-striped
|
||||||
|
%thead
|
||||||
|
%tr
|
||||||
|
%th= Link.human_attribute_name :name
|
||||||
|
%th= Link.human_attribute_name :url
|
||||||
|
%th= t 'ui.actions'
|
||||||
|
%tbody
|
||||||
|
- for link in @links
|
||||||
|
%tr
|
||||||
|
%td= link.name
|
||||||
|
%td= link.url
|
||||||
|
%td
|
||||||
|
= link_to t('ui.edit'), edit_admin_link_path(link), remote: true, class: 'btn btn-mini'
|
||||||
|
= link_to t('ui.delete'), admin_link_path(link), :data => {:confirm => t('admin.confirm', name: link.name)},
|
||||||
|
:method => :delete, class: 'btn btn-mini btn-danger'
|
2
plugins/links/app/views/admin/links/edit.js.haml
Normal file
2
plugins/links/app/views/admin/links/edit.js.haml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
$('#modalContainer').html('#{j(render("form"))}');
|
||||||
|
$('#modalContainer').modal();
|
7
plugins/links/app/views/admin/links/index.html.haml
Normal file
7
plugins/links/app/views/admin/links/index.html.haml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
- title t '.title'
|
||||||
|
|
||||||
|
- content_for :actionbar do
|
||||||
|
= link_to t('.new_link'), new_admin_link_path, remote: true, class: 'btn btn-primary'
|
||||||
|
|
||||||
|
#links
|
||||||
|
= render "links"
|
2
plugins/links/app/views/admin/links/update_links.js.haml
Normal file
2
plugins/links/app/views/admin/links/update_links.js.haml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
$('#links').html('#{escape_javascript(render("links"))}');
|
||||||
|
$('#modalContainer').modal('hide');
|
|
@ -1,6 +1,25 @@
|
||||||
de:
|
de:
|
||||||
|
activerecord:
|
||||||
|
attributes:
|
||||||
|
link:
|
||||||
|
name: Name
|
||||||
|
url: URL
|
||||||
|
workgroup: Arbeitsgruppe
|
||||||
|
indirect: Indirekt
|
||||||
|
authorization: Authorization-Header
|
||||||
|
admin:
|
||||||
|
links:
|
||||||
|
index:
|
||||||
|
title: Links
|
||||||
|
new_link: Neuen Link hinzufügen
|
||||||
|
form:
|
||||||
|
title_new: Link hinzufügen
|
||||||
|
title_edit: Link bearbeiten
|
||||||
|
description: Wenn eine Arbeitsgruppe ausgewählt ist, dann ist der Link nur für deren Mitglieder sichtbar. Die Option Indirekt ermöglicht es, dass die Foodsoft Nutzer_innen an die bei von der URL zurück gegebene Adresse weiterleitet. Diese Option sollte nur bei genauem Verständnis der Funktion aktiviert werden.
|
||||||
links:
|
links:
|
||||||
show:
|
show:
|
||||||
indirect_no_location: Die konfigurierte URL hat keinen Location Header für die Weiterleitung zurück gegeben.
|
indirect_no_location: Die konfigurierte URL hat keinen Location Header für die Weiterleitung zurück gegeben.
|
||||||
navigation:
|
navigation:
|
||||||
|
admin:
|
||||||
|
links: Links
|
||||||
links: Links
|
links: Links
|
||||||
|
|
|
@ -1,6 +1,23 @@
|
||||||
en:
|
en:
|
||||||
|
activerecord:
|
||||||
|
attributes:
|
||||||
|
link:
|
||||||
|
name: Name
|
||||||
|
url: URL
|
||||||
|
workgroup: Workgroup
|
||||||
|
indirect: Indirect
|
||||||
|
authorization: Authorization-Header
|
||||||
|
admin:
|
||||||
|
links:
|
||||||
|
index:
|
||||||
|
title: Links
|
||||||
|
new_link: Add new link
|
||||||
|
form:
|
||||||
|
description: If a workgroup is selected, the link is only visible to its members. The option Indirect allows it, that the Foodsoft will redirect users to the address returned by the URL. This option should only be activated if the exact functionality is understood correctly.
|
||||||
links:
|
links:
|
||||||
show:
|
show:
|
||||||
indirect_no_location: The configured URL did not return a Location header for redirection.
|
indirect_no_location: The configured URL did not return a Location header for redirection.
|
||||||
navigation:
|
navigation:
|
||||||
|
admin:
|
||||||
|
links: Links
|
||||||
links: Links
|
links: Links
|
||||||
|
|
|
@ -4,6 +4,10 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :links, only: [:show]
|
resources :links, only: [:show]
|
||||||
|
|
||||||
|
namespace :admin do
|
||||||
|
resources :links
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,16 @@ module FoodsoftLinks
|
||||||
if i = primary.items.index(primary[:admin])
|
if i = primary.items.index(primary[:admin])
|
||||||
primary.items.insert(i, primary.items.delete_at(-1))
|
primary.items.insert(i, primary.items.delete_at(-1))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless primary[:admin].nil?
|
||||||
|
sub_nav = primary[:admin].sub_navigation
|
||||||
|
sub_nav.items <<
|
||||||
|
SimpleNavigation::Item.new(primary, :links, I18n.t('navigation.admin.links'), context.admin_links_path)
|
||||||
|
# move to right before config item
|
||||||
|
if i = sub_nav.items.index(sub_nav[:config])
|
||||||
|
sub_nav.items.insert(i, sub_nav.items.delete_at(-1))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def visble_links(context)
|
def visble_links(context)
|
||||||
|
|
Loading…
Reference in a new issue