Skip to content

Commit

Permalink
Add default and current project columns to list
Browse files Browse the repository at this point in the history
  • Loading branch information
gangelo committed Jan 28, 2024
1 parent a2706ef commit f28c765
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 29 deletions.
11 changes: 7 additions & 4 deletions lib/dsu/subcommands/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ class Project < BaseSubcommand

desc I18n.t('subcommands.project.create.desc'), I18n.t('subcommands.project.create.usage')
long_desc I18n.t('subcommands.project.create.long_desc')
option :project_name, type: :string, required: true, aliases: '-n', banner: 'PROJECT_NAME'
option :description, type: :string, required: false, aliases: '-d', banner: 'DESCRIPTION'
option :prompts, type: :hash, default: {}, hide: true, aliases: '-p'
def create
project_name = options[:project_name]
description = options[:description]
def create(project_name = nil)
description = options[:description].to_s.strip
project_name = project_name.to_s.strip
if project_name.blank?
return Views::Shared::Error.new(messages: I18n.t('subcommands.project.create.messages.project_name_blank')).render
end

presenter = Presenters::Project::CreatePresenter.new(project_name: project_name,
description: description, options: options)
Views::Project::Create.new(presenter: presenter, options: options).render
Expand Down
45 changes: 38 additions & 7 deletions lib/dsu/views/project/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ module Views
module Project
# TODO: I18n.
class List < Views::BaseListView
DETAIL_HEADER_STRING = "#{'No.'.ljust(4)} " \
"#{'Project'.ljust(15)} " \
"#{'Description'.ljust(10)}".freeze
NO_JUSTIFICATION = 4
PROJECT_JUSTIFICATION = 15
DEFAULT_JUSTIFICATION = 10
CURRENT_JUSTIFICATION = 10
DESCRIPTION_JUSTIFICATION = 10

DETAIL_HEADER_STRING = "#{'No.'.ljust(NO_JUSTIFICATION)} " \
"#{'Project'.ljust(PROJECT_JUSTIFICATION)} " \
"#{'Default'.center(DEFAULT_JUSTIFICATION)} " \
"#{'Current'.center(CURRENT_JUSTIFICATION)} " \
"#{'Description'.ljust(DESCRIPTION_JUSTIFICATION)}".freeze

def render
super do
Expand Down Expand Up @@ -39,6 +47,8 @@ def display_detail
display_detail_data(
formatted_index(index: index),
project.project_name,
project.default_project?,
project.current_project?,
project.description
)
end
Expand All @@ -48,12 +58,23 @@ def display_detail_header
puts apply_theme(DETAIL_HEADER_STRING, theme_color: color_theme.index)
end

def display_detail_data(index, project_name, project_desc)
def display_detail_data(index, project_name, default_project, current_project, project_desc)
puts "#{index_detail_data(index)} " \
"#{project_name_detail_data(project_name)} " \
"#{project_default_detail_data(default_project)} " \
"#{project_current_detail_data(current_project)} " \
"#{project_desc_detail_data(project_desc)}"
end

# def display_detail_data(index, project_name, default_project, current_project, project_desc)
# puts "#{index_detail_data(index)}|" \
# "#{project_name_detail_data(project_name)}|" \
# "#{project_default_detail_data(default_project)}|" \
# "#{project_current_detail_data(current_project)}|" \
# "#{project_desc_detail_data(project_desc)}"
# end


def display_footer
footer = "\nTotal projects: #{presenter.projects.count}"
puts apply_theme(footer, theme_color: color_theme.footer)
Expand All @@ -65,15 +86,25 @@ def display_header
end

def index_detail_data(value)
apply_theme(value.to_s.ljust(4), theme_color: color_theme.index)
apply_theme(value.to_s.ljust(NO_JUSTIFICATION), theme_color: color_theme.index)
end

def project_name_detail_data(value)
apply_theme(value.to_s.ljust(15), theme_color: color_theme.body.bold!)
apply_theme(value.to_s.ljust(PROJECT_JUSTIFICATION), theme_color: color_theme.body.bold!)
end

def project_default_detail_data(value)
value = value ? '*' : ' '
apply_theme(value.to_s.center(DEFAULT_JUSTIFICATION), theme_color: color_theme.body.bold!)
end

def project_current_detail_data(value)
value = value ? '*' : ' '
apply_theme(value.to_s.center(CURRENT_JUSTIFICATION), theme_color: color_theme.body.bold!)
end

def project_desc_detail_data(value)
apply_theme(value.to_s.ljust(10), theme_color: color_theme.body)
apply_theme(value.to_s.ljust(DESCRIPTION_JUSTIFICATION), theme_color: color_theme.body)
end

def theme_name
Expand Down
59 changes: 41 additions & 18 deletions lib/locales/en/subcommands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -474,29 +474,32 @@ en:
$ dsu list y
project:
create:
desc: create|c OPTIONS
usage: Creates a DSU project using the given OPTIONS
desc: create|c PROJECT_NAME [OPTIONS]
usage: Creates a DSU project using the given PROJECT_NAME and OPTIONS
long_desc: |
Creates a DSU project using the given OPTIONS.
Creates a DSU project using the given PROJECT_NAME and OPTIONS.
dsu project create OPTIONS
dsu project create PROJECT_NAME [OPTIONS]
dsu p c OPTIONS
dsu p c PROJECT_NAME [OPTIONS]
OPTIONS:
PROJECT_NAME:
The name of the project to create. PROJECT_NAME must be between 2 and 12 characters (inclusive) in length.
-n|--name PROJECT_NAME: The name of the project to create. PROJECT_NAME must be between 2 and 12 characters (inclusive) in length.
OPTIONS:
-d|--description DESCRIPTION: Optional. The description of the project. DESCRIPTION must be between 2 and 256 characters (inclusive) in length. If DESCRIPTION is not provided, the project description will be "<PROJECT_NAME> project" where <PROJECT_NAME> = the name of the project.
EXAMPLES:
$ dsu project create -n "My project" -d "My project description"
$ dsu project create "My project" --description "My project description"
$ dsu p c -n "My project"
$ dsu p c "My project" -d "My project description"
messages:
created: Created project "%{project_name}".
already_exists: Project "%{project_name}" already exists.
project_name_blank: No value provided for project name.
prompts:
create_confirm: Create project "%{project_name}"?
create_options:
Expand All @@ -507,24 +510,44 @@ en:
- y
- n
delete:
desc: delete|d OPTIONS
usage: Permanently deletes the DSU project indicated by the given OPTIONS
desc: delete|d [PROJECT_NAME | PROJECT_NUMBER]
usage: Permanently deletes the DSU project indicated by the optional PROJECT_NAME or PROJECT_NUMBER
long_desc: |
Permanently deletes the DSU project indicated by the given OPTIONS.
Permanently deletes the DSU project indicated by given option PROJECT_NAME or PROJECT_NUMBER.
dsu project delete OPTIONS
dsu project delete [PROJECT_NAME | PROJECT_NUMBER]
dsu p d OPTIONS
dsu p d [PROJECT_NAME | PROJECT_NUMBER]
OPTIONS:
PROJECT_NAME:
-n|--name PROJECT_NAME: The name of the project to delete.
The name of the project to delete.
PROJECT_NUMBER:
The number of the project to delete. If PROJECT_NUMBER is used, the project equating to the nth project in the list of projects will be used (see `dsu project list`).
NOTES
PROJECT_NAME and PROJECT_NUMBER are optional. If neither are provided, the current, default project will be used.
EXAMPLES:
$ dsu project delete -n "My project"
$ dsu project delete "My project"
$ dsu p d "My project"
# The below examples delete the project equating to the nth project in the list of projects (see `dsu project list`).
$ dsu project delete 2
$ dsu p d 2
# The below examples delete the current, default project.
$ dsu project delete
$ dsu p d -n "My project"
$ dsu p d
messages:
deleted: Deleted project "%{project_name}".
prompts:
Expand Down

0 comments on commit f28c765

Please sign in to comment.