Add description to type defaults

pull/7287/head
Oliver Günther 6 years ago
parent fa8288ef16
commit 9d7837d472
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 1
      app/contracts/types/base_contract.rb
  2. 2
      app/models/permitted_params.rb
  3. 8
      app/views/types/form/_settings.html.erb
  4. 1
      config/locales/en.yml
  5. 5
      db/migrate/20190509071101_add_default_description_to_types.rb
  6. 2
      frontend/src/app/components/work-packages/wp-single-view/wp-single-view.html
  7. 13
      frontend/src/app/components/wp-edit-form/work-package-changeset.ts
  8. 2
      frontend/src/app/modules/fields/edit/edit-field.component.ts
  9. 17
      frontend/src/app/modules/fields/edit/field-types/formattable-edit-field.component.ts
  10. 9
      lib/api/v3/work_packages/work_package_representer.rb
  11. 1
      spec/factories/type_factory.rb
  12. 68
      spec/features/work_packages/new/work_package_default_description_spec.rb

@ -43,6 +43,7 @@ module Types
attribute :is_default attribute :is_default
attribute :color_id attribute :color_id
attribute :project_ids attribute :project_ids
attribute :description
attribute :attribute_groups attribute :attribute_groups
validate :validate_current_user_is_admin validate :validate_current_user_is_admin

@ -606,6 +606,8 @@ class PermittedParams
:is_milestone, :is_milestone,
:is_default, :is_default,
:color_id, :color_id,
:default,
:description,
project_ids: [] project_ids: []
], ],
user: %i( user: %i(

@ -55,6 +55,14 @@ See docs/COPYRIGHT.rdoc for more details.
container_class: '-slim') %> container_class: '-slim') %>
</div> </div>
<% end %> <% end %>
<div class="form--field">
<%= f.text_area :description,
class: 'wiki-edit wiki-toolbar',
container_class: '-xxwide',
with_text_formatting: true %>
</div>
<!--[eoform:type]--> <!--[eoform:type]-->
</div> </div>

@ -435,6 +435,7 @@ en:
spent_on: "Date" spent_on: "Date"
type: "Type" type: "Type"
type: type:
description: "Default text for description"
attribute_groups: '' attribute_groups: ''
is_in_roadmap: "Displayed in roadmap by default" is_in_roadmap: "Displayed in roadmap by default"
is_default: "Activated for new projects by default" is_default: "Activated for new projects by default"

@ -0,0 +1,5 @@
class AddDefaultDescriptionToTypes < ActiveRecord::Migration[5.2]
def change
add_column :types, :description, :text
end
end

@ -40,7 +40,7 @@
<div class="attributes-group--header-container"></div> <div class="attributes-group--header-container"></div>
</div> </div>
<div> <div>
<p [hidden]="projectContext.href" [textContent]="text.project.required"></p> <p class="wp-project-context--warning" [hidden]="projectContext.href" [textContent]="text.project.required"></p>
<div class="attributes-key-value" <div class="attributes-key-value"
[ngClass]="{'-span-all-columns': descriptor.spanAll }" [ngClass]="{'-span-all-columns': descriptor.spanAll }"
*ngFor="let descriptor of projectContext.field; trackBy:trackByName"> *ngFor="let descriptor of projectContext.field; trackBy:trackByName">

@ -87,6 +87,16 @@ export class WorkPackageChangeset {
this.resetForm(); this.resetForm();
} }
/**
* Remove some of the changes by key
* @param changes
*/
public clearSome(...changes:string[]) {
changes.forEach((key) => {
delete this.changes[key];
});
}
public resetForm() { public resetForm() {
this.form = null; this.form = null;
} }
@ -156,6 +166,7 @@ export class WorkPackageChangeset {
.update(payload) .update(payload)
.then((form:FormResource) => { .then((form:FormResource) => {
this.form = form; this.form = form;
this.workPackage.$initialize({ ...form.payload.$source, id: this.workPackage.id });
this.buildResource(); this.buildResource();
@ -359,7 +370,7 @@ export class WorkPackageChangeset {
return; return;
} }
let payload:any = this.workPackage.$source; let payload:any = this.workPackage.$plain();
const resource = this.halResourceService.createHalResourceOfType('WorkPackage', this.mergeWithPayload(payload)); const resource = this.halResourceService.createHalResourceOfType('WorkPackage', this.mergeWithPayload(payload));

@ -60,7 +60,7 @@ export class EditFieldComponent extends Field implements OnInit, OnDestroy {
public self = this; public self = this;
/** JQuery accessor to element ref */ /** JQuery accessor to element ref */
protected $element:JQuery<HTMLElement>; protected $element:JQuery;
constructor(readonly I18n:I18nService, constructor(readonly I18n:I18nService,
readonly elementRef:ElementRef, readonly elementRef:ElementRef,

@ -131,6 +131,8 @@ export class FormattableEditFieldComponent extends EditFieldComponent implements
} }
public reset() { public reset() {
this.changeset.clearSome(this.name);
if (this.instance) { if (this.instance) {
this.instance.content = this.rawValue; this.instance.content = this.rawValue;
} }
@ -155,4 +157,19 @@ export class FormattableEditFieldComponent extends EditFieldComponent implements
public get isFormattable() { public get isFormattable() {
return true; return true;
} }
protected initialize() {
if (this.resource.isNew && this.instance) {
this.instance
.getTransformedContent()
.then((val) => {
// Reset CKEditor when reloading after type/form changes
if (!val) {
this.reset();
}
this.rawValue = val;
});
}
}
} }

@ -324,7 +324,14 @@ module API
property :description, property :description,
exec_context: :decorator, exec_context: :decorator,
getter: ->(*) { getter: ->(*) {
::API::Decorators::Formattable.new(represented.description, object: represented) type = represented&.type
description = represented&.description
if !description.present? && type&.description
::API::Decorators::Formattable.new(type.description, object: represented)
else
::API::Decorators::Formattable.new(description, object: represented)
end
}, },
setter: ->(fragment:, **) { setter: ->(fragment:, **) {
represented.description = fragment['raw'] represented.description = fragment['raw']

@ -30,6 +30,7 @@ FactoryBot.define do
factory :type do factory :type do
sequence(:position) { |p| p } sequence(:position) { |p| p }
name { |a| "Type No. #{a.position}" } name { |a| "Type No. #{a.position}" }
description { nil }
created_at { Time.now } created_at { Time.now }
updated_at { Time.now } updated_at { Time.now }

@ -0,0 +1,68 @@
require 'spec_helper'
require 'support/work_packages/work_package_field'
require 'features/work_packages/work_packages_page'
require 'features/page_objects/notification'
describe 'new work package', js: true do
let(:type_task) { FactoryBot.create(:type_task, description: "# New Task template\n\nHello there") }
let!(:status) { FactoryBot.create(:status, is_default: true) }
let!(:priority) { FactoryBot.create(:priority, is_default: true) }
let!(:project) do
FactoryBot.create(:project, types: [type_task])
end
let(:user) { FactoryBot.create :admin }
let(:subject_field) { wp_page.edit_field :subject }
let(:description_field) { wp_page.edit_field :description }
let(:project_field) { wp_page.edit_field :project }
let(:type_field) { wp_page.edit_field :type }
let(:notification) { PageObjects::Notifications.new(page) }
let(:wp_page) { Pages::FullWorkPackageCreate.new }
before do
login_as(user)
end
describe 'global work package create' do
it 'shows the template after selection of project and type' do
visit '/work_packages/new'
wp_page.expect_fully_loaded
project_field.openSelectField
project_field.set_value project
subject_field.set_value 'Foobar!'
# Wait until project is set
expect(page).to have_no_selector('.wp-project-context--warning')
type_field.openSelectField
type_field.set_value type_task
scroll_to_and_click find('#work-packages--edit-actions-save')
wp_page.expect_notification message: 'Successful creation.'
expect(page).to have_selector('.wp-edit-field--display-field.description h1', text: 'New Task template')
end
end
describe 'project work package create' do
let(:wp_table) { Pages::WorkPackagesTable.new project }
let(:wp_page) { Pages::SplitWorkPackageCreate.new project: project }
it 'shows the template after selection of project and type' do
wp_table.visit!
wp_table.create_wp_split_screen type_task
wp_page.expect_fully_loaded
subject_field.set_value 'Foobar!'
scroll_to_and_click find('#work-packages--edit-actions-save')
wp_page.expect_notification message: 'Successful creation.'
expect(page).to have_selector('.wp-edit-field--display-field.description h1', text: 'New Task template')
end
end
end
Loading…
Cancel
Save