Initial commit

This commit is contained in:
Senad Uka
2021-09-20 08:22:39 +02:00
commit a0c72b0caf
133 changed files with 9056 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
//= link_tree ../images
//= link_directory ../stylesheets .css

0
app/assets/images/.keep Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 239 KiB

View File

@@ -0,0 +1,2 @@
//= require jquery
//= require rails.validations

View File

@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end

View File

@@ -0,0 +1,4 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end

View File

@@ -0,0 +1,2 @@
class ApplicationController < ActionController::Base
end

View File

View File

@@ -0,0 +1,2 @@
module ApplicationHelper
end

View File

@@ -0,0 +1,5 @@
class ImportantInput < Formtastic::Inputs::StringInput
def to_html
(" IMPORTANT " + super + " IMPORTANT ").html_safe
end
end

View File

@@ -0,0 +1,6 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `bin/rails generate channel` command.
import { createConsumer } from "@rails/actioncable"
export default createConsumer()

View File

@@ -0,0 +1,5 @@
// Load all the channels within this directory and all subdirectories.
// Channel files must be named *_channel.js.
const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)

View File

@@ -0,0 +1,13 @@
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"
Rails.start()
Turbolinks.start()
ActiveStorage.start()

View File

@@ -0,0 +1,7 @@
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
end

View File

@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end

6
app/models/admin_user.rb Normal file
View File

@@ -0,0 +1,6 @@
class AdminUser < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :validatable
end

View File

@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

View File

@@ -0,0 +1,7 @@
module Recentable
extend ActiveSupport::Concern
included do
scope :recent, ->(number) { order("created_at DESC").limit(number) }
end
end

8
app/models/employer.rb Normal file
View File

@@ -0,0 +1,8 @@
class Employer < ApplicationRecord
include Recentable
has_many :subscriptions
end

3
app/models/product.rb Normal file
View File

@@ -0,0 +1,3 @@
class Product < ApplicationRecord
belongs_to :supplier
end

110
app/models/subscription.rb Normal file
View File

@@ -0,0 +1,110 @@
class Subscription < ApplicationRecord
include Recentable
belongs_to :employer
belongs_to :series_successor, class_name: "Subscription", foreign_key: :series_successor_id, optional: true, inverse_of: :series_predecessor
has_one :series_predecessor, -> { readonly }, class_name: "Subscription", foreign_key: :series_successor_id, inverse_of: :series_successor, dependent: :nullify
validates :name, length: { in: 2..255, allow_nil: true }
validates :autorenew_duration, numericality: { greater_than: 0 }
validates :starts_at, presence: true
validate :ends_at_after_starts_at
validate :ends_at_before_successor_starts
validate :starts_at_after_predecessor_ends
validate :autorenew_voided_at_after_starts_at
validate :terminated_at_after_starts_at
validate :autorenew_deadline_after_starts_at_and_before_ends_at
validates :billing_frequency, presence: true
def ends_at_after_starts_at
return if ends_at.blank? || starts_at.blank?
if ends_at < starts_at
errors.add(:ends_at, "must be after the start date")
end
end
def ends_at_before_successor_starts
return if series_successor.blank?
if ends_at.blank?
errors.add(:ends_at, "is required for renewed records")
return
end
if ends_at >= series_successor.starts_at
errors.add(:ends_at, "must be before its renewal's start date")
end
end
def starts_at_after_predecessor_ends
return if series_predecessor.blank?
if starts_at.blank?
errors.add(:starts_at, "is required for records with predecessors")
return
end
if starts_at <= series_predecessor.ends_at
errors.add(:starts_at, "must be after its predecessor's end date")
end
end
# Either percentage or flat fare discount type must be set if product is in travel vertical
def discount_type_set
# If product not yet set, can't assume discount type not being set is an error
return if !product
if has_percentage_discount_type.blank? && has_flat_fare_discount_type.blank?
errors.add(:has_percentage_discount_type, "- At least one of has_percentage_discount_type and has_flat_fare_discount_type must be true")
end
end
# HACK: this is a temporary fix to work around the lack of atomic updates
# for subscriptions and cycles.
# TODO: https://concertiv.atlassian.net/browse/ENG-266 - fix by using Form Objects
def sync_effective_at
return if self.cycles.empty?
if self.cycles.length == 1
self.cycles.first.effective_at = self.starts_at
end
end
def terminated_at_after_starts_at
return if terminated_at.blank? || starts_at.blank?
if terminated_at < starts_at
errors.add(:terminated_at, "must be after the start date")
end
end
def autorenew_voided_at_after_starts_at
return if !is_autorenew
return if autorenew_voided_at.blank? || starts_at.blank?
if autorenew_voided_at < starts_at
errors.add(:autorenew_voided_at, "must be after the start date")
end
end
def autorenew_deadline_after_starts_at_and_before_ends_at
return if !is_autorenew
if autorenew_deadline.blank?
errors.add(:autorenew_deadline, "must be a valid date")
return
end
if !starts_at.blank? && autorenew_deadline < starts_at
errors.add(:autorenew_deadline, "must be after the start date")
end
if !ends_at.blank? && autorenew_deadline > ends_at
errors.add(:autorenew_deadline, "must be before the end date")
end
end
end

3
app/models/supplier.rb Normal file
View File

@@ -0,0 +1,3 @@
class Supplier < ApplicationRecord
has_many :products
end

View File

@@ -0,0 +1,14 @@
<h1>Completely custom form</h1>
<%= semantic_form_for [:admin, @employer] do |f| %>
<%= f.inputs do %>
<%= f.input :name, as: :important %>
<%= f.input :logo_url %>
<%= f.input :short_name %>
<%= f.input :short_code %>
<%= f.input :status, as: :select, collection: ["active","inactive"], include_blank: false %>
<% end %>
<%= f.actions %>
<% end %>

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>Ssrconcept</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%= yield %>
</body>
</html>

View File

@@ -0,0 +1 @@
<%= yield %>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" "http-equiv"="Content-Type">
<meta content="NONE,NOARCHIVE" name="robots">
<%= csrf_meta_tag %>
<%= stylesheet_link_tag "rails_admin/rails_admin.css", :media => :all %>
<%= javascript_include_tag "rails_admin/rails_admin.js" %>
</head>
<body class="rails_admin">
<div id="loading" class="label label-warning" style="display:none; position:fixed; right:20px; bottom:20px; z-index:100000">
<%= t('admin.loading') %>
</div>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<%= link_to dashboard_path, class: "brand pjax" do %>
<%= _get_plugin_name[0] || 'Rails' %>
<small><%= _get_plugin_name[1] || 'Admin' %>
<% end %>
<div class="nav-collapse">
<%= render :partial => 'layouts/rails_admin/secondary_navigation' %>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<%= main_navigation %>
</ul>
<ul class="nav nav-list">
<%= static_navigation %>
</ul>
</div>
</div>
<div class="span9">
<div class="row-fluid">
<div class="content" data-pjax-container="1">
<%= render :template => 'layouts/rails_admin/pjax' %>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<%= errors_summary_for broadcast %>
<%= bootstrap_form_with model: model, local: true do |form| %>
V <%= form.text_field :name %>
<%= form.time_zone_select(:shoot_location_time_zone, nil, label: "Time zone of shoot location") %> <div class="row align-items-center text-center mt-4">
<%= link_to t("shared.cancel"), [project, :broadcasts], class: "col-3 text-reset" %>
<div class="col-9">
<%= form.submit class: class_string("btn btn-block", ["btn-success", "btn-primary"] => broadcast.new_record?), data: { disable_with: t("shared.disable_with") } %>
</div>
</div>
<% end %>