Skip to content

Commit

Permalink
Merge branch 'develop' into feature/fix_event
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashnikovisme committed Jan 17, 2020
2 parents d9da89a + 281dea9 commit 4712866
Show file tree
Hide file tree
Showing 56 changed files with 322 additions and 99 deletions.
1 change: 1 addition & 0 deletions Readme.md
Expand Up @@ -64,6 +64,7 @@ Tramway решает две проблемы:
## Products

* [IT Way](http://it-way.pro)
* [Molodoy.online](http://molodoy.online)
* [Peklo Tool](https://tool.peklo.studio/)
* [kalashnikovisme.ru](http://kalashnikovisme.ru)
* [МБУ ДО ДЮСШ Ленинского района](http://sportschool-ulsk.ru/) (не поддерживается)
Expand Down
16 changes: 16 additions & 0 deletions tramway-admin/README.md
Expand Up @@ -29,6 +29,7 @@ gem 'trap'
gem 'kaminari'
gem 'bootstrap-kaminari-views', github: 'kalashnikovisme/bootstrap-kaminari-views', branch: :master
gem 'state_machine_buttons'
gem 'ckeditor', '4.2.4'
```

You should remove gem `turbolinks` from your application
Expand Down Expand Up @@ -84,6 +85,21 @@ window.current_locale = window.i18n_locale 'en'
```
to the `app/assets/javascripts/admin/application.js.coffee` file

## Notifications

You can add notification to your admin panel to the navbar.

To add notification to application, you need just set queries in initializers.

*config/initializers/tramway.rb*
```ruby
::Tramway::Admin.set_notificable_queries :"#{your_title}" => -> { your_query }

# Example from tramway-event gem

::Tramway::Admin.set_notificable_queries new_participants: -> { ::Tramway::Event::Participant.active.where(participation_state: :requested) }
```

## Contributing
Contribution directions go here.

Expand Down
Expand Up @@ -13,3 +13,12 @@

td.actions
width: 8rem

.icon-in-navbar
font-size: 15pt

.notifications
a
margin-right: 25px
span.badge:hover
filter: brightness(90%)
Expand Up @@ -12,6 +12,8 @@ class ApplicationController < ::Tramway::Core::ApplicationController
before_action :collections_counts, if: :model_given?
before_action :check_available_scope!, if: :model_given?, only: :index
before_action :application
before_action :notifications
before_action :notifications_count

protect_from_forgery with: :exception

Expand Down Expand Up @@ -39,6 +41,17 @@ def application
end
end

def notifications
@notifications ||= Tramway::Admin.notifications
@notifications
end

def notifications_count
@notifications_count = notifications.reduce(0) do |count, notification|
count += notification[1].count
end
end

if Rails.env.production?
rescue_from StandardError do |exception|
Rails.logger.warn "ERROR MESSAGE: #{exception.message}"
Expand Down
Expand Up @@ -15,6 +15,22 @@
= model_menu_item model: model, route: ::Tramway::Admin::Engine.routes.url_helpers.records_path(model: model, scope: decorator_class(model).collections.first)
%ul.nav.navbar-nav.ml-auto
- if signed_in?
- if @notifications_count > 0
%li.nav-item.dropdown.notifications
= link_to '#', class: 'nav-link icon-in-navbar dropdown-toggle', id: :notifications_dropdown, role: :button, aria: { haspopup: true, expanded: false }, data: { toggle: :dropdown } do
%span.badge.badge-light
= @notifications_count
.dropdown-menu.dropdown-menu-right{ aria: { labelledby: :notifications_dropdown } }
- @notifications.each_with_index do |collection, index|
- collection[1].each do |item|
= link_to decorator_class(item.class).decorate(item).title, record_path(item, model: item.class), class: 'dropdown-item'
- if index < @notifications.count - 1
.dropdown-divider
- else
%li.nav-item.notifications
= link_to '#', class: 'nav-link icon-in-navbar' do
%span.badge.badge-light
= @notifications_count
%li.nav-item
= link_to Tramway::Auth::Engine.routes.url_helpers.session_path, method: :delete, class: 'nav-link' do
= fa_icon 'sign-out-alt'
Expand Down
11 changes: 11 additions & 0 deletions tramway-admin/lib/tramway/admin.rb
Expand Up @@ -86,6 +86,17 @@ def project_is_engine?(project)
def get_models_by_key(checked_models, project)
checked_models && checked_models != [] && checked_models[project.to_sym] || []
end

def set_notificable_queries(**queries)
@notificable_queries ||= {}
@notificable_queries.merge! queries
end

def notifications
@notificable_queries&.reduce({}) do |hash, notification|
hash.merge! notification[0] => notification[1].call
end
end
end
end
end
2 changes: 1 addition & 1 deletion tramway-admin/lib/tramway/admin/version.rb
Expand Up @@ -2,6 +2,6 @@

module Tramway
module Admin
VERSION = '1.18.4.3'
VERSION = '1.19.0.2'
end
end
1 change: 0 additions & 1 deletion tramway-admin/tramway-admin.gemspec
Expand Up @@ -19,7 +19,6 @@ Gem::Specification.new do |s|
s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']

s.add_dependency 'bootstrap-kaminari-views', '0.0.5'
s.add_dependency 'ckeditor', '4.2.4'
s.add_dependency 'copyright_mafa', '~> 0.1.2', '>= 0.1.2'
s.add_dependency 'font-awesome-rails', '~> 4.7', '>= 4.7.0.1'
s.add_dependency 'kaminari', '~> 1.1.1', '>= 1.1.1'
Expand Down
2 changes: 1 addition & 1 deletion tramway-conference/Gemfile
Expand Up @@ -15,7 +15,7 @@ gem 'font-awesome-rails'
gem 'haml-rails'
gem 'jquery-rails'
gem 'kaminari'
gem 'loofah', '~> 2.2.1'
gem 'loofah', '>= 2.3.1'
gem 'mini_magick'
gem 'pg', '0.21.0'
gem 'rails-html-sanitizer', '~> 1.0.4'
Expand Down
@@ -1,5 +1,6 @@
#= require jquery
#= require jquery_ujs
#= require popper
#= require bootstrap-datepicker-1.8.0
#= require bootstrap-datepicker-1.8.0.ru.min
#= require font_awesome5
Expand Down Expand Up @@ -27,4 +28,3 @@ $(document).ready ->
anchor = $(this).data('anchor')
unless $(anchor).offset() == undefined
$(window).scrollTop $(anchor).offset().top

Expand Up @@ -3,6 +3,11 @@
module Tramway
module Core
class ApplicationController < ActionController::Base
before_action :application

def application
@application = ::Tramway::Core.application_object
end
end
end
end
2 changes: 1 addition & 1 deletion tramway-core/app/helpers/tramway/core/title_helper.rb
Expand Up @@ -8,7 +8,7 @@ def title(page_title = default_title)
title_text = "#{page_title} | #{@application.try(:title) || @application.public_name}"
content_for(:title) { title_text }
else
error = Tramway::Error.new(plugin: :core, method: :title, message: 'You should set Tramway::Core::Application class using `::Tramway::Core.initialize_application model_class: #{model_class_name}` in config/initializers/tramway.rb OR may be you don\'t have any records of application model')
error = Tramway::Error.new(plugin: :core, method: :title, message: 'You should set Tramway::Core::Application class using `::Tramway::Core.initialize_application model_class: #{model_class_name}` in config/initializers/tramway.rb OR maybe you don\'t have any records of application model')
raise error.message
end
end
Expand Down
8 changes: 6 additions & 2 deletions tramway-core/lib/tramway/collections/helper.rb
Expand Up @@ -4,9 +4,13 @@ module Tramway
module Collections
module Helper
def collection_list_by(name:)
require name # needed to load class name with collection
begin
require name # needed to load class name with collection
rescue LoadError
raise "No such file #{name}. You should create file in the `lib/#{name}.rb` or elsewhere you want"
end
unless ::Tramway::Collection.descendants.map(&:to_s).include?(name.camelize)
raise "There no such collection named #{name.camelize}. Please create class with self method `list` and extended of `Tramway::Collection`"
raise "There no such collection named #{name.camelize}. Please create class with self method `list` and extended of `Tramway::Collection`. You should reload your server after creating this collection."
end

name.camelize.constantize.list
Expand Down
10 changes: 9 additions & 1 deletion tramway-core/lib/tramway/core.rb
Expand Up @@ -20,7 +20,15 @@ def initialize_application(**options)
end

def application_object
@application.model_class.present? ? @application.model_class.first : @application
if @application&.model_class.present?
begin
@application.model_class.first
rescue
nil
end
else
@application
end
end

attr_reader :application
Expand Down
2 changes: 1 addition & 1 deletion tramway-core/lib/tramway/core/application.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Tramway::Core::Application
attr_accessor :name, :url, :model_class, :title, :tagline, :found_date
attr_accessor :name, :url, :model_class, :title, :tagline, :found_date, :phone, :email

def public_name
name.to_s.gsub('_', ' ').camelize
Expand Down
2 changes: 1 addition & 1 deletion tramway-core/lib/tramway/core/version.rb
Expand Up @@ -2,6 +2,6 @@

module Tramway
module Core
VERSION = '1.14.5.2'
VERSION = '1.14.7.2'
end
end
3 changes: 2 additions & 1 deletion tramway-core/tramway-core.gemspec
Expand Up @@ -21,11 +21,12 @@ Gem::Specification.new do |s|
s.add_dependency 'audited', '>= 4.8.0'
s.add_dependency 'bootstrap', '>= 4.1.2'
s.add_dependency 'carrierwave'
s.add_dependency 'ckeditor', '4.2.4'
s.add_dependency 'enumerize', '~> 2.1', '>= 2.1.2'
s.add_dependency 'font_awesome5_rails'
s.add_dependency 'haml-rails', '~> 1.0', '>= 1.0.0'
s.add_dependency 'kaminari'
s.add_dependency 'loofah', '~> 2.2', '>= 2.2.1'
s.add_dependency 'loofah', '>= 2.3.1'
s.add_dependency 'mini_magick', '~> 4.8', '>= 4.8.0'
s.add_dependency 'pg_search'
s.add_dependency 'reform'
Expand Down
22 changes: 14 additions & 8 deletions tramway-event/README.md
Expand Up @@ -5,36 +5,42 @@ Short description and motivation.
How to use my plugin.

## Installation
Add this line to your application's Gemfile:

#### 1. Add this line to your application's Gemfile:

```ruby
gem 'tramway-event'
gem 'carrierwave'
gem 'more_html_tags'
```

And then execute:
#### 2. And then execute:
```bash
$ bundle
```
*Gemfile*
```ruby
gem 'tramway-event'
```

Then run:
#### 3. Then run:
```shell
rails g tramway:event:install
rails db:migrate
```

Then make `tramway-landing` installation. [How-to](https://github.com/ulmic/tramway-dev/blob/develop/tramway-landing/README.md#installation)
#### 4. Then make `tramway-landing` installation. [How-to](https://github.com/ulmic/tramway-dev/blob/develop/tramway-landing/README.md#installation)

#### 5. Add events to admin panel

*config/initializers/tramway.rb*
```ruby
Tramway::Admin.set_available_models ::Tramway::Event::Event, ::Tramway::Event::ParticipantFormField, ::Tramway::Event::Participant, project: #{project_which_you_used_in_the_application}
```

#### 6. Add events routes to the app

*config/routes.rb*
```ruby
mount Tramway::Event::Engine, at: '/'
```

## Contributing
Contribution directions go here.

Expand Down
@@ -1 +1,4 @@
//= require tramway/core/application
//= require_tree .

window.current_locale = window.i18n_locale('ru');
10 changes: 6 additions & 4 deletions tramway-event/app/controllers/tramway/event/events_controller.rb
Expand Up @@ -12,10 +12,12 @@ def show
@footer = ::Tramway::Landing::BlockDecorator.decorate ::Tramway::Landing::Block.footer
@events = ::Tramway::Event::Event.active.actual.map { |e| ::Tramway::Event::Events::Show::EventDecorator.decorate e }
@people_as_features = @event.partakings.active.map { |p| ::Tramway::Event::PartakingFeatureDecorator.decorate p }
@partners = ::Tramway::Partner::Partnership.partnership_type.values.reduce({}) do |hash, partnership_type|
hash.merge! partnership_type => (event.send(partnership_type.to_s.pluralize).active.map do |partner|
Tramway::Partner::OrganizationFeatureDecorator.decorate partner
end)
if defined?(::Tramway::Partner)
@partners = ::Tramway::Partner::Partnership.partnership_type.values.reduce({}) do |hash, partnership_type|
hash.merge! partnership_type => (event.send(partnership_type.to_s.pluralize).active.map do |partner|
Tramway::Partner::OrganizationFeatureDecorator.decorate partner
end)
end
end
end
end
Expand Up @@ -4,7 +4,10 @@ class Tramway::Event::ParticipantExtendedFormCreator < Tramway::Core::FormCreato
def self.create_form_class(uuid, event, **simple_properties)
class_name = "ParticipantExtendedForm#{uuid.gsub('-', '')}"
properties = event.participant_form_fields.inputs_list.reduce({}) do |hash, field|
hash.merge! field.title.to_sym => { object: field, validates: field.options['validations'] }
hash.merge! field.title.to_sym => {
object: field,
validates: (field.options == '' ? {} : field.options)&.dig('validations')
}
end
if simple_properties.keys.any?
::Tramway::Core::ExtendableForm.new(class_name, simple_properties: simple_properties, **properties)
Expand Down
Expand Up @@ -5,14 +5,14 @@ class Tramway::Event::ParticipantFormFieldForm < ::Tramway::Core::ApplicationFor
association :event

def initialize(object)
form_object = super object
form_properties event: :association,
title: :string,
description: :string,
field_type: :default,
options: :text,
position: :numeric
form_object
super(object).tap do
form_properties event: :association,
title: :string,
description: :string,
field_type: :default,
options: :text,
position: :numeric
end
end

def options
Expand Down
Expand Up @@ -7,9 +7,9 @@
%hr/
%p.mb-0
По всем вопросам обращайтесь по телефону
= tel_tag '+79603727276'
= tel_tag @application.phone
или пишите на email
= mail_to 'kalashnikov@ulmic.ru'
= mail_to @application.email
- if params[:flash] == 'error'
.alert.alert-danger{ role: "alert" }
%button.close{"aria-label" => "Close", "data-dismiss" => "alert", type: "button"}
Expand All @@ -19,9 +19,9 @@
%hr/
%p.mb-0
Если ошибка повторяется или не отображается, обращайтесь по телефону
= tel_tag '+79603727276'
= tel_tag @application.phone
или пишите на email
= mail_to 'kalashnikov@ulmic.ru'
= mail_to @application.email
- if request.path == ::Tramway::Event::Engine.routes.url_helpers.event_path(event.id)
= render 'tramway/landing/blocks/templates/full_page', block: event, buttons: [OpenStruct.new(title: t('.registration'), anchor: '#registration')]
- content_for :main_image do
Expand All @@ -39,5 +39,6 @@
- if index < sections.count - 1
%br
= render 'tramway/landing/blocks/templates/features_list', block: OpenStruct.new(title: "Оргкомитет", description: "", anchor: :organizers), collection: people_as_features, options: { image: { css: { class_name: 'circle' } } }
- ::Tramway::Partner::Partnership.partnership_type.values.each do |partnership_type|
= render 'tramway/landing/blocks/templates/features_list', block: OpenStruct.new(title: t("enumerize.tramway/partner/partnership.partnership_type.#{partnership_type}")), collection: partners[partnership_type]
- if defined? ::Tramway::Partner
- ::Tramway::Partner::Partnership.partnership_type.values.each do |partnership_type|
= render 'tramway/landing/blocks/templates/features_list', block: OpenStruct.new(title: t("enumerize.tramway/partner/partnership.partnership_type.#{partnership_type}")), collection: partners[partnership_type]
2 changes: 2 additions & 0 deletions tramway-event/app/views/tramway/event/events/show.html.haml
@@ -1,5 +1,7 @@
- content_for :title do
= @event.title
- content_for :head_content do
= javascript_include_tag 'tramway/event/application'
- content_for :footer_links do
%ul
- @events.each do |event|
Expand Down
1 change: 1 addition & 0 deletions tramway-event/config/initializers/tramway.rb
Expand Up @@ -8,3 +8,4 @@
::Tramway::Event::Partaking,
::Tramway::Event::Place,
project: :event)
::Tramway::Admin.set_notificable_queries new_participants: -> { ::Tramway::Event::Participant.active.where(participation_state: :requested) }

0 comments on commit 4712866

Please sign in to comment.