delay linking attachments for wiki pages

pull/6446/head
Jens Ulferts 6 years ago
parent c7b54471d3
commit afc5211ca6
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 18
      app/controllers/wiki_controller.rb
  2. 1
      frontend/src/app/components/attachments/attachment-list/attachment-list-item.component.ts
  3. 2
      frontend/src/app/components/attachments/attachment-list/attachment-list-item.html
  4. 4
      frontend/src/app/components/attachments/attachment-list/attachment-list.html
  5. 6
      frontend/src/app/components/attachments/attachments-upload/attachments-upload.component.ts
  6. 2
      frontend/src/app/components/ckeditor/op-ckeditor-form.component.ts
  7. 4
      frontend/src/app/modules/hal/resources/mixins/attachable-mixin.ts
  8. 4
      frontend/src/app/modules/hal/resources/wiki-page-resource.ts

@ -185,8 +185,6 @@ class WikiController < ApplicationController
@page.attach_files(permitted_params.attachments.to_h)
return if nothing_to_update?
@page.title = permitted_params.wiki_page[:title]
@page.parent_id = permitted_params.wiki_page[:parent_id].to_i
@content.attributes = permitted_params.wiki_content
@ -378,22 +376,6 @@ class WikiController < ApplicationController
private
def nothing_to_update?
return false if @page.new_record?
if anything_to_update?
render_attachment_warning_if_needed(@page)
# don't save if text wasn't changed
redirect_to_show
true
end
end
def anything_to_update?
params[:content].present? &&
@content.text == permitted_params.wiki_content[:text] &&
@page.parent_id == permitted_params.wiki_page[:parent_id].to_i
end
def locked?
return false if editable?

@ -40,6 +40,7 @@ import {States} from 'core-components/states.service';
export class AttachmentListItemComponent {
@Input('resource') public resource:HalResource;
@Input('attachment') public attachment:any;
@Input() public index:any;
public text = {
destroyConfirmation: this.I18n.t('js.text_attachment_destroy_confirmation'),

@ -22,4 +22,6 @@
<op-icon icon-classes="icon-delete"
[icon-title]="text.removeFile({fileName: attachment.fileName})"></op-icon>
</a>
<input type="hidden" name="attachments[{{index}}][id]" value="{{attachment.id}}" *ngIf="!attachment.container">
</li>

@ -1,6 +1,6 @@
<div class="work-package--attachments--files" *ngIf="resource">
<ul class="form--selected-value--list"
*ngFor="let attachment of resource.attachments.elements">
<attachment-list-item [attachment]="attachment" [resource]="resource"></attachment-list-item>
*ngFor="let attachment of resource.attachments.elements; let i = index;">
<attachment-list-item [attachment]="attachment" [resource]="resource" [index]="i"></attachment-list-item>
</ul>
</div>

@ -62,12 +62,6 @@ export class AttachmentsUploadComponent implements OnInit {
ngOnInit() {
this.$element = jQuery(this.elementRef.nativeElement);
if (!this.resource) {
// Parse the resource if any exists
const source = this.$element.data('resource');
this.resource = this.halResourceService.createHalResource(source, true);
}
this.ConfigurationService.api().then((settings:any) => {
this.maxFileSize = settings.maximumAttachmentFileSize;
});

@ -145,7 +145,7 @@ export class OpCkeditorFormComponent implements OnInit, OnDestroy {
private setupAttachmentAddedCallback() {
this.ckeditor.model.on('op:attachment-added', () => {
this.states.wikiPages.get(this.resource!.id).putValue(this.resource);
this.states.wikiPages.get(this.resource!.id).putValue(this.resource!);
});
}

@ -50,6 +50,8 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {
private opFileUpload:OpenProjectFileUploadService;
private pathHelper:PathHelperService;
private attachmentsLinkImmediately:boolean;
/**
* Remove the given attachment either from the pending attachments or from
* the attachment collection, if it is a resource.
@ -103,7 +105,7 @@ export function Attachable<TBase extends Constructor<HalResource>>(Base:TBase) {
private performUpload(files:UploadFile[]) {
let href = '';
if (!this.id) {
if (!this.id || !this.attachmentsLinkImmediately) {
href = this.pathHelper.api.v3.attachments.path;
} else {
href = this.addAttachment.$link.href;

@ -35,9 +35,11 @@ export interface WikiPageResourceLinks {
class WikiPageBaseResource extends HalResource {
public $links:WikiPageResourceLinks;
private attachmentsLinkImmediately = false;
}
export const WikiPageResource = Attachable(WikiPageBaseResource);
export interface WikiPageResource extends WikiPageBaseResource {
export interface WikiPageResource extends HalResource {
}

Loading…
Cancel
Save