diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 344a583e7..e0d7c2979 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -27,6 +27,7 @@ class Dossier < ActiveRecord::Base has_many :invites, dependent: :destroy has_many :invites_user, class_name: 'InviteUser', dependent: :destroy has_many :follows + has_many :notifications, dependent: :destroy belongs_to :procedure belongs_to :user diff --git a/app/models/notification.rb b/app/models/notification.rb new file mode 100644 index 000000000..3a48600cc --- /dev/null +++ b/app/models/notification.rb @@ -0,0 +1,4 @@ +class Notification < ActiveRecord::Base + belongs_to :dossier + +end diff --git a/app/views/backoffice/dossiers/_list.html.haml b/app/views/backoffice/dossiers/_list.html.haml index a06af02e0..db57cf6fd 100644 --- a/app/views/backoffice/dossiers/_list.html.haml +++ b/app/views/backoffice/dossiers/_list.html.haml @@ -1,5 +1,8 @@ %table#dossiers_list.table %thead + - if smart_listing.name.to_s == 'follow_dossiers' + %th + %i.fa.fa-bell - @facade_data_view.preference_list_dossiers_filter.each do |preference| %th{class: "col-md-#{preference.bootstrap_lg} col-lg-#{preference.bootstrap_lg}"} - if preference.table.to_s.include? 'champs' @@ -16,6 +19,15 @@ - unless smart_listing.empty? - smart_listing.collection.each do |dossier| %tr{id: "tr_dossier_#{dossier.id}", 'data-dossier_url' => backoffice_dossier_url(id: dossier.id)} + - if smart_listing.name.to_s == 'follow_dossiers' + %td.center + - total_notif = dossier.notifications.count + - if total_notif == 0 + .badge.progress-bar-default + = total_notif + - else + .badge.progress-bar-danger + = total_notif - @facade_data_view.preference_list_dossiers_filter.each_with_index do |preference, index| %td - if preference.table.nil? || preference.table.empty? diff --git a/db/migrate/20161221153929_create_notification.rb b/db/migrate/20161221153929_create_notification.rb new file mode 100644 index 000000000..745086412 --- /dev/null +++ b/db/migrate/20161221153929_create_notification.rb @@ -0,0 +1,16 @@ +class CreateNotification < ActiveRecord::Migration[5.0] + def change + create_table :notifications do |t| + + t.boolean :already_read, default: false + t.string :liste, array: true + t.boolean :multiple, default: false + t.string :type_notif + t.datetime :created_at + t.datetime :updated_at + + end + + add_belongs_to :notifications, :dossier + end +end diff --git a/db/schema.rb b/db/schema.rb index dbbb43529..924830524 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161205110427) do +ActiveRecord::Schema.define(version: 20161221153929) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -249,6 +249,17 @@ ActiveRecord::Schema.define(version: 20161205110427) do t.index ["procedure_id"], name: "index_module_api_cartos_on_procedure_id", unique: true, using: :btree end + create_table "notifications", force: :cascade do |t| + t.boolean "already_read", default: false + t.string "liste", array: true + t.boolean "multiple", default: false + t.string "type_notif" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "dossier_id" + t.index ["dossier_id"], name: "index_notifications_on_dossier_id", using: :btree + end + create_table "pieces_justificatives", force: :cascade do |t| t.string "content" t.integer "dossier_id" diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 5fe22ff6e..4349748ad 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -27,6 +27,7 @@ describe Dossier do it { is_expected.to belong_to(:user) } it { is_expected.to have_many(:invites) } it { is_expected.to have_many(:follows) } + it { is_expected.to have_many(:notifications) } end describe 'delegation' do diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb new file mode 100644 index 000000000..8adf11ab2 --- /dev/null +++ b/spec/models/notification_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Notification do + it { is_expected.to have_db_column(:already_read) } + it { is_expected.to have_db_column(:liste) } + it { is_expected.to have_db_column(:multiple) } + it { is_expected.to have_db_column(:type_notif) } + it { is_expected.to have_db_column(:created_at) } + it { is_expected.to have_db_column(:updated_at) } + + it { is_expected.to belong_to(:dossier) } +end