From 0ff05754c580df0898008909c65fb6d66e9a9cb8 Mon Sep 17 00:00:00 2001 From: JUDIS <61043700+judis007@users.noreply.github.com> Date: Wed, 23 Feb 2022 11:31:44 +0530 Subject: [PATCH] New project functionality (#120) --- app/controllers/projects_controller.rb | 17 ++++++++ app/javascript/stylesheets/application.scss | 6 +++ app/models/project.rb | 4 +- app/views/projects/_new.html.erb | 42 +++++++++++++++++++ app/views/projects/index.html.erb | 25 ++++++++--- config/locales/en.yml | 14 ++++++- config/routes.rb | 3 +- ..._constraint_for_description_in_projects.rb | 11 +++++ db/schema.rb | 14 ++++++- spec/models/project_spec.rb | 1 - 10 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 app/views/projects/_new.html.erb create mode 100644 db/migrate/20220210103446_remove_not_null_constraint_for_description_in_projects.rb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 22fe6bc726..8ad6b7b8b5 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -7,4 +7,21 @@ def index @query = Project.ransack(params[:q]) @projects = @query.result(distinct: true) end + + def create + project = Project.new(project_params) + + if project.save + flash[:notice] = t(".success") + else + flash[:alert] = t(".failure") + end + + redirect_to projects_path + end + + private + def project_params + params.require(:project).permit(:client_id, :name, :billable) + end end diff --git a/app/javascript/stylesheets/application.scss b/app/javascript/stylesheets/application.scss index 1806dc7219..dd7a4001a3 100644 --- a/app/javascript/stylesheets/application.scss +++ b/app/javascript/stylesheets/application.scss @@ -41,12 +41,18 @@ &__button { @apply tracking-widest inline-flex items-center h-10 w-full flex justify-center py-1 px-4 border border-transparent shadow-sm text-base font-bold text-miru-white-1000 bg-miru-han-purple-1000 hover:bg-miru-han-purple-600 focus:outline-none rounded; } + &__button_outline { + @apply ml-2 tracking-widest inline-flex items-center h-10 w-full flex justify-center py-1 px-4 border-2 border-miru-han-purple-1000 shadow-sm bg-transparent hover:border-miru-han-purple-600 focus:outline-none rounded text-base font-semibold text-miru-han-purple-1000 bg-transparent hover:text-miru-han-purple-600 cursor-pointer; + } &__error { @apply tracking-wider block text-xs font-semibold text-red-600; } &__link { @apply font-bold text-miru-han-purple-1000 hover:text-miru-han-purple-600 tracking-wider; } + &__radio { + @apply focus:ring-miru-han-purple-1000 h-4 w-4 border-miru-han-purple-1000 text-miru-dark-purple-1000; + } } .password_eye { diff --git a/app/models/project.rb b/app/models/project.rb index cca110c0d6..731b814395 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -5,7 +5,7 @@ # id :integer not null, primary key # client_id :integer not null # name :string not null -# description :text not null +# description :text # billable :boolean not null # created_at :datetime not null # updated_at :datetime not null @@ -28,7 +28,7 @@ class Project < ApplicationRecord has_many :project_members, dependent: :destroy # Validations - validates :name, :description, presence: true + validates :name, presence: true validates :billable, inclusion: { in: [ true, false ] } # Callbacks diff --git a/app/views/projects/_new.html.erb b/app/views/projects/_new.html.erb new file mode 100644 index 0000000000..d7ebc12aac --- /dev/null +++ b/app/views/projects/_new.html.erb @@ -0,0 +1,42 @@ +<%= form_with model: Project.new do |f| %> +
+
+ <%= f.label t('projects.client') %> +
+ <%= f.collection_select :client_id, current_company.clients.order(:name),:id,:name, {}, { class: "rounded tracking-wider appearance-none border border-gray-100 block w-full px-3 py-2 bg-miru-white-100 h-8 shadow-sm font-semibold text-xs text-miru-dark-purple-1000 focus:outline-none focus:ring-miru-gray-1000 focus:border-miru-gray-1000" } %> +
+
+
+ +
+
+ <%= f.label t('projects.project_name') %> +
+ <%= f.text_field :name, class: "form__input" %> +
+
+
+ +
+
+
+
+
+ <%= f.radio_button :billable, true, class: "form__radio" %> + <%= f.label :billable, t('projects.billable'), class: "form__label" %> +
+ +
+ <%= f.radio_button :billable, false, class: "form__radio" %> + <%= f.label :billable, t('projects.non_billable'), class: "form__label" %> +
+
+
+
+
+ +
+ <%= f.submit t('projects.add_project').upcase, class: "form__button" %> +
+<% end %> + diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index d99b51f091..3d10602124 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -6,7 +6,7 @@

- <%= t('project.projects') %> + <%= t('projects.projects') %>

@@ -20,7 +20,7 @@ <% if policy(Project).create? %>
- @@ -37,7 +37,7 @@ - <%= t('project.project_client') %> + <%= t('projects.project').upcase %>/<%= t('projects.client').upcase %> <%= t('project.hours_logged') %> @@ -46,7 +46,7 @@ - Edit + <%= t('projects.edit') %> @@ -72,5 +72,20 @@
+ +
+
+
+
+
+
<%= t('projects.add_new_project').capitalize %>
+ +
+ <%= render "projects/new"%> +
+
+
- \ No newline at end of file + + + diff --git a/config/locales/en.yml b/config/locales/en.yml index 0ddb4eeed1..74be3a946e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -42,11 +42,21 @@ en: team: Team time_tracking: Time Tracking view_notifications: View Notifications - project: + projects: projects: Projects hours_logged: HOURS LOGGED new_project: NEW PROJECT - project_client: PROJECT/CLIENT + project: Project + client: Client + project_name: Project name + edit: edit + create: + success: Project added successfully. + failure: Project creation failed. + add_project: Add project + add_new_project: Add new project + billable: Billable + non_billable: Non-Billable companies: create: failure: "Company creation failed" diff --git a/config/routes.rb b/config/routes.rb index 754783ee98..8a34b2a148 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,7 +33,8 @@ def draw(routes_name) resources :time_tracking, only: [:index], path: "time-tracking" resources :team, only: [:index, :update, :destroy, :edit] resources :clients, only: [:index, :create] - resources :projects, only: [:index] + resources :projects, only: [:index, :create] + devise_scope :user do get "profile", to: "users/registrations#edit" diff --git a/db/migrate/20220210103446_remove_not_null_constraint_for_description_in_projects.rb b/db/migrate/20220210103446_remove_not_null_constraint_for_description_in_projects.rb new file mode 100644 index 0000000000..00515bb123 --- /dev/null +++ b/db/migrate/20220210103446_remove_not_null_constraint_for_description_in_projects.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class RemoveNotNullConstraintForDescriptionInProjects < ActiveRecord::Migration[7.0] + def up + change_column_null :projects, :description, true + end + + def down + change_column_null :projects, :description, false + end +end diff --git a/db/schema.rb b/db/schema.rb index 8e9ef7f5b7..e7a5b95525 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -91,7 +91,7 @@ create_table "projects", force: :cascade do |t| t.bigint "client_id", null: false t.string "name", null: false - t.text "description", null: false + t.text "description" t.boolean "billable", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false @@ -110,6 +110,16 @@ t.index ["resource_type", "resource_id"], name: "index_roles_on_resource" end + create_table "team_members", force: :cascade do |t| + t.bigint "user_id", null: false + t.bigint "project_id", null: false + t.decimal "hourly_rate", default: "0.0", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["project_id"], name: "index_team_members_on_project_id" + t.index ["user_id"], name: "index_team_members_on_user_id" + end + create_table "timesheet_entries", force: :cascade do |t| t.bigint "user_id", null: false t.bigint "project_id", null: false @@ -177,6 +187,8 @@ add_foreign_key "project_members", "projects" add_foreign_key "project_members", "users" add_foreign_key "projects", "clients" + add_foreign_key "team_members", "projects" + add_foreign_key "team_members", "users" add_foreign_key "timesheet_entries", "projects" add_foreign_key "timesheet_entries", "users" add_foreign_key "users", "companies" diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 90c72aa7ea..f2f47eb092 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -12,7 +12,6 @@ describe "Validations" do it { is_expected.to validate_presence_of(:name) } - it { is_expected.to validate_presence_of(:description) } it { is_expected.to validate_inclusion_of(:billable).in_array([true, false]) } end