use angular based attachments component

pull/6827/head
Jens Ulferts 6 years ago
parent a141b90e48
commit dc1681f361
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 8
      app/views/documents/_form.html.erb
  2. 25
      app/views/documents/show.html.erb
  3. 4
      frontend/module/hal/resources/document-resource.ts
  4. 4
      frontend/module/main.ts
  5. 17
      lib/api/v3/documents/document_representer.rb
  6. 8
      spec/features/attachment_upload_spec.rb

@ -31,6 +31,10 @@ See doc/COPYRIGHT.rdoc for more details.
++#%>
<%= error_messages_for 'document' %>
<% resource = ::API::V3::Documents::DocumentRepresenter.new(f.object,
current_user: current_user,
embed_links: true) %>
<div class="form--field">
<%= f.select :category_id,
DocumentCategory.all.map { |c| [c.name, c.id] },
@ -44,7 +48,7 @@ See doc/COPYRIGHT.rdoc for more details.
<%= f.text_area :description,
container_class: '-xxwide',
with_text_formatting: true,
resource: { _type: 'Document' },
resource: resource,
preview_context: preview_context(f.object.project) %>
</div>
<%= render :partial => 'attachments/form' %>
<attachments data-resource="<%= resource.to_json %>" data-allow-uploading="true"></attachments>

@ -53,25 +53,8 @@ See doc/COPYRIGHT.rdoc for more details.
<%= format_text @document.description, attachments: @document.attachments %>
</div>
<h3><%= l(:label_attachment_plural) %></h3>
<%= link_to_attachments @document %>
<% if authorize_for('documents', 'add_attachment') %>
<p>
<%= link_to_function l(:label_attachment_new),
%{
jQuery('#add_attachment_form').show();
jQuery(this).hide();
jQuery('#add_attachment_form')[0].scrollIntoView();
},
id: 'attach_files_link' %>
</p>
<%= form_tag(add_attachment_document_path(@document), method: :post, multipart: true, id: "add_attachment_form", style: "display:none;") do %>
<div class="box">
<p><%= render partial: 'attachments/form' %></p>
</div>
<%= styled_button_tag l(:button_add), class: "-highlight -with-icon icon-checkmark" %>
<% end %>
<% end %>
<% resource = ::API::V3::Documents::DocumentRepresenter.new(@document,
current_user: current_user,
embed_links: true) %>
<attachments data-resource="<%= resource.to_json %>" data-allow-uploading="false"></attachments>

@ -40,9 +40,11 @@ export interface DocumentResourceLinks {
class DocumentBaseResource extends HalResource {
public $links:DocumentResourceLinks;
private attachmentsBackend = false;
}
export const DocumentResource = Attachable(DocumentBaseResource);
export interface DocumentResource extends DocumentResourceLinks {
export interface DocumentResource extends DocumentBaseResource {
}

@ -32,6 +32,7 @@
import {APP_INITIALIZER, Injector, NgModule} from '@angular/core';
import {OpenProjectPluginContext} from "core-app/modules/plugins/plugin-context";
import {DocumentResource} from './hal/resources/document-resource';
import {multiInput} from 'reactivestates';
export function initializeDocumentPlugin() {
return () => {
@ -39,6 +40,9 @@ export function initializeDocumentPlugin() {
.then((pluginContext:OpenProjectPluginContext) => {
let halResourceService = pluginContext.services.halResource;
halResourceService.registerResource('Document', { cls: DocumentResource });
let states = pluginContext.services.states;
states.add('documents', multiInput<DocumentResource>());
});
};
}

@ -34,24 +34,11 @@ module API
module Documents
class DocumentRepresenter < ::API::Decorators::Single
include API::Decorators::LinkedResource
include API::Caching::CachedRepresenter
include ::API::V3::Attachments::AttachableRepresenterMixin
self_link title_getter: ->(*) { represented.title }
link :attachments do
{
href: api_v3_paths.attachments_by_document(represented.id)
}
end
link :addAttachment do
next unless current_user_allowed_to(:manage_documents, context: represented.project)
{
href: api_v3_paths.attachments_by_document(represented.id),
method: :post
}
end
property :id
property :title

@ -70,6 +70,8 @@ describe 'Upload attachment to documents', js: true do
editable.find('figure.image figcaption').base.send_keys('Image uploaded on creation')
end
expect(page).to have_selector('attachment-list-item', text: 'image.png')
click_on 'Create'
expect(page).to have_selector('#content img', count: 1)
@ -77,8 +79,6 @@ describe 'Upload attachment to documents', js: true do
click_on 'New documentation'
expect(page).to have_selector('.attachments', text: 'image.png')
within '.toolbar-items' do
click_on 'Edit'
end
@ -91,11 +91,13 @@ describe 'Upload attachment to documents', js: true do
editable.find('figure.image figcaption').base.send_keys('Image uploaded the second time')
end
expect(page).to have_selector('attachment-list-item', text: 'image.png', count: 2)
click_on 'Save'
expect(page).to have_selector('#content img', count: 2)
expect(page).to have_content('Image uploaded on creation')
expect(page).to have_content('Image uploaded the second time')
expect(page).to have_selector('.attachments a', text: 'image.png', count: 2)
expect(page).to have_selector('attachment-list-item', text: 'image.png', count: 2)
end
end

Loading…
Cancel
Save