Skip to content

Commit

Permalink
add send to municipality button
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Dec 14, 2017
1 parent f763dee commit b84da88
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
.meta {
float:left;
}
.permissions {
.thread-parameters {
float:right;
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/assets/stylesheets/shared_elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ul.thread-list {
padding-left:42px;
background: image-url("map-icons/m-roadworks.png") 0 20px no-repeat;
}
.permissions {
.permissions, .external-service {
float:right;
}
}
Expand All @@ -278,7 +278,7 @@ ul.thread-list {
}
}

.permissions {
.thread-parameters {
width: 80px;
color: $lightgrey;
text: {
Expand Down
44 changes: 44 additions & 0 deletions app/controllers/admin/external_services_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Admin::ExternalServicesController < ApplicationController
def index
@external_services = ExternalService.all
end

def new
@external_service = ExternalService.new
end

def create
@external_service = ExternalService.new(permitted_params)
puts @external_service

if @external_service.save
set_flash_message(:success)
redirect_to action: :index
else
render :new
end
end

def edit
external_service
end

def update
if external_service.update permitted_params
set_flash_message :success
redirect_to action: :index
else
render :edit
end
end

protected

def permitted_params
params.require(:external_service).permit :name, :short_name
end

def external_service
@external_service ||= ExternalService.find params[:id]
end
end
18 changes: 18 additions & 0 deletions app/controllers/issue/message_threads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ def new
@message = @thread.messages.build
@message.body = issue.description if issue.threads.count == 0
@available_groups = current_user.groups
@external_services = ExternalService.all
end

helper_method :new_external

def new_external
@thread = issue.threads.build
set_page_title nil, issue: issue.title
if current_group
@thread.group = current_group
@thread.privacy = current_group.default_thread_privacy
end
@message = @thread.messages.build
@message.body = issue.description
@thread.title = issue.title
@thread.privacy = "public"
@available_groups = current_user.groups
@external_services = ExternalService.all
end

def create
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/message_threads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def thread
end

def permitted_params
params.require(:thread).permit :title, :privacy, :group_id, :issue_id, :tags_string
params.require(:thread).permit :title, :privacy, :group_id, :issue_id, :tags_string, :external_service_id
end

def permitted_message_params
Expand Down
27 changes: 27 additions & 0 deletions app/models/external_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# == Schema Information
#
# Table name: external_services
#
# id :integer not null, primary key
# name :string(255) not null
# short_name :string(255) not null
#
# Indexes
#
# index_external_services_on_short_name (short_name)
#

class ExternalService < ActiveRecord::Base
has_many :threads, class_name: 'MessageThread', inverse_of: :external_service

validates :name, presence: true, uniqueness: true
validates :short_name, presence: true, uniqueness: true, subdomain: true

normalize_attributes :short_name, with: [:strip, :blank, :downcase]

def to_param
"#{id}-#{short_name}"
end

protected
end
2 changes: 2 additions & 0 deletions app/models/message_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MessageThread < ActiveRecord::Base
belongs_to :group, inverse_of: :threads, counter_cache: true
belongs_to :issue, inverse_of: :threads
belongs_to :user, inverse_of: :private_threads
belongs_to :external_service, inverse_of: :threads
has_many :messages, -> { order('created_at ASC') }, foreign_key: 'thread_id', autosave: true, inverse_of: :thread
has_many :subscriptions, -> { where(deleted_at: nil) }, class_name: 'ThreadSubscription', foreign_key: 'thread_id', inverse_of: :thread
has_many :subscribers, through: :subscriptions, source: :user
Expand Down Expand Up @@ -322,6 +323,7 @@ def as_json(_options = nil)
created_by_id: created_by_id,
created_by_name: created_by.profile.visibility == 'public' ? created_by.name : nil,
group_id: group_id,
external_service: external_service ? external_service.short_name : nil,
created_at: created_at,
updated_at: updated_at,
deleted_at: deleted_at,
Expand Down
7 changes: 7 additions & 0 deletions app/views/admin/external_services/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= semantic_form_for @external_service, url: [:admin, @external_service] do |f|
= f.inputs do
= f.input :name, input_html: { size: 30 }
= f.input :short_name, input_html: { size: 30 }
= f.actions do
= f.action :submit, button_html: {class: "btn-green submit"}
= cancel_link
5 changes: 5 additions & 0 deletions app/views/admin/external_services/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%header
%h1
= t ".edit_external_service"
%section
= render "form"
15 changes: 15 additions & 0 deletions app/views/admin/external_services/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%header
%h1= t ".title"
%section
.tasks
%p= link_to t(".new_external_service"), new_admin_external_service_path
%table
%thead
%th= t ".name"
%th= t ".short_name"
%tbody
- @external_services.each do |external_service|
%tr
%td= external_service.name
%td= external_service.short_name
%td= link_to t(".edit"), [:edit, :admin, external_service]
5 changes: 5 additions & 0 deletions app/views/admin/external_services/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%header
%h1= t ".title"
%p= t ".introduction"
%section
= render "form"
1 change: 1 addition & 0 deletions app/views/admin/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
%li= link_to t(".manage_users"), admin_users_path
%li= link_to t(".manage_comments"), site_comments_path
%li= link_to t(".manage_message_moderations"), admin_message_moderations_path
%li= link_to t(".manage_external_services"), admin_external_services_path
%li= link_to t(".manage_site_config"), admin_site_config_path
%li= link_to 'Stats', admin_stats_path
%li= link_to 'Resque', resque_server_path
Expand Down
25 changes: 25 additions & 0 deletions app/views/issue/message_threads/new_external.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
%section.new-thread
%h2= t ".title", issue: @issue.title.truncate(50)
- if @issue.threads.count == 0
%div.meta
%p
%i= simple_format t ".new_hint"
= semantic_form_for @thread, as: :thread, url: {action: :create}, html: {class: 'guided'} do |f|
= f.semantic_errors
= f.inputs do
= f.input :title
- if @available_groups.present?
= f.input :group,
collection: @available_groups.map {|g| [g.name, g.id, "data-privacy" => g.default_thread_privacy, "data-privacy-options" => Hash[g.thread_privacy_options_map_for(current_user).map { |n,v| [v, n]}].to_json] },
include_blank: false
- if @external_services.present?
= f.input :external_service,
as: :select,
collection: @external_services.map {|g| [g.name, g.id] },
include_blank: false
= semantic_fields_for @message do |f2|
= f2.semantic_errors
= f2.input :body, input_html: { rows: 10 }
= f.actions do
= f.action :submit, button_html: {class: "btn-green submit", data: { disable_with: t("formtastic.actions.saving") }}
= cancel_link issue_path(@issue)
4 changes: 4 additions & 0 deletions app/views/issues/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
%aside#sidebar.wide
- if permitted_to? :create, :issue_message_threads
= link_to t(".new_thread", count: @issue.threads.count), new_issue_thread_path(@issue), class: "btn-green", rel: "#overlay"
- if current_user and current_user.groups.present?
- if ExternalService.all.present?
- if permitted_to? :create, :issue_message_threads
= link_to t(".new_send_thread", count: @issue.threads.count), issue_threads_new_external_path(@issue), class: "btn-green", rel: "#overlay"
%section.social
= tweet_button text: @issue.title, link: issue_url(@issue)
= facebook_like issue_url(@issue)
Expand Down
5 changes: 4 additions & 1 deletion app/views/message_threads/_compact.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
= thread.latest_activity_by.display_name_or_anon
= time_tag_with_title(thread.latest_activity_at) do
- t ".posted_at", time_ago: time_ago_in_words(thread.latest_activity_at)
.permissions= thread_type(thread)
.thread-parameters
- if thread.external_service
.external-service= thread.external_service.name
.permissions= thread_type(thread)
1 change: 1 addition & 0 deletions app/views/message_threads/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- unless f.object.private_message?
= f.input :group
= f.input :privacy, as: :select, collection: f.object.class.privacies_map
= f.input :external_service
= f.input :issue, as: :select, collection: Issue.by_most_recent.map { |iss| ["#{iss.id} - #{iss.title}", iss.id] }
= f.actions do
= f.action :submit, button_html: {class: "btn-green submit", data: { disable_with: t("formtastic.actions.saving") }}
Expand Down
3 changes: 2 additions & 1 deletion config/authorization_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
includes :member
has_permission_on :group_members, :group_memberships, :group_membership_requests, :group_profiles, :group_prefs, to: :manage
has_permission_on :admin_groups, to: [:manage, :disable, :enable]
has_permission_on :admin_external_services, to: :manage
has_permission_on :group_requests do
to [:index, :review, :confirm, :reject, :destroy]
end
Expand Down Expand Up @@ -82,7 +83,7 @@
has_permission_on :messages, to: [:new, :create, :vote_up, :vote_clear]
has_permission_on :message_library_notes, to: [:new, :create]
has_permission_on :message_library_documents, to: [:new, :create]
has_permission_on :issue_message_threads, to: [:new, :create]
has_permission_on :issue_message_threads, to: [:new, :new_external, :create]
has_permission_on :group_message_threads do
to [:new, :create]
if_attribute group: is_in { user.groups }
Expand Down
20 changes: 20 additions & 0 deletions config/locales/cs-CZ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,24 @@ cs-CZ:
manage_issue_categories: Spravovat kategorie podnětů
manage_users: Spravovat uživatele
manage_message_moderations: Spravovat moderované zprávy
manage_external_services: Spravovat externí služby
manage_site_config: Manage site config
external_services:
create:
success: Externí služba vytvořena
new:
title: Nová externí služba
introduction: Vytvořit novou externí službu
edit:
edit_external_service: Upravit externí službu
update:
success: Externí služba upravena
index:
name: Jméno
short_name: Identifikátor
title: Externí služby
new_external_service: Nová externí služba
edit: Upravit nastavení
issue_categories:
create:
success: Kategorie vytvořena
Expand Down Expand Up @@ -661,6 +678,8 @@ cs-CZ:
do lesa.
title: Nové vlákno na téma %{issue}
everyone: Každý
new_external:
title: Odeslat podnět "%{issue}" na úřad
photos:
show:
photo_alt: Fotka pro %{caption}.
Expand Down Expand Up @@ -721,6 +740,7 @@ cs-CZ:
zero: Diskutujte
one: Nové diskuzní vlákno
other: Nové diskuzní vlákno
new_send_thread: Odeslat na úřad
no_threads_yet: O tomto podnětu zatím neexistují žádná diskuzní vlákna.
group_private: Soukromé pro %{group}
group_public: Veřejné od %{group}
Expand Down
19 changes: 19 additions & 0 deletions config/locales/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@
manage_users: Manage users
manage_message_moderations: Manage message moderations
manage_site_config: Manage site config
external_services:
create:
success: External service created
new:
title: New external service
introduction: Create new external service
edit:
edit_external_service: Edit external service
update:
success: External service updated
index:
name: Name
short_name: Identifier
title: External services
new_external_service: New external service
edit: Edit preferences
issue_categories:
create:
success: Category created
Expand Down Expand Up @@ -561,6 +577,8 @@
access to woods."
title: New Thread on %{issue}
everyone: Everyone
new_external:
title: Send issue "%{issue}" to municipality
photos:
show:
photo_alt: The photo for %{caption}.
Expand Down Expand Up @@ -622,6 +640,7 @@
zero: Discuss
one: New Thread
other: New Thread
new_send_thread: Send to municipality
no_threads_yet: There are no discussion threads for this issue yet.
group_private: Private to %{group}
group_public: Public, by %{group}
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def issues_route(opts = {})
get :all_geometries, on: :collection
scope module: 'issue' do
resource :photo, only: [:show]
get "/threads/new_external", to: "message_threads#new_external"
resources :threads, controller: 'message_threads'
resource :tags, only: [:update]
end
Expand Down Expand Up @@ -49,6 +50,7 @@ def issues_route(opts = {})
resources :groups do
put :disable, :enable, on: :member
end
resources :external_services
resource :site_config
resources :stats, only: :index
resources :message_moderations, only: :index
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddSubmitExternalToMessageThread < ActiveRecord::Migration
def change
add_column :message_threads, :external_service_id, :integer
create_table :external_services do |t|
t.string :name, null: false
t.string :short_name, null: false
end
end
end

0 comments on commit b84da88

Please sign in to comment.