[CUBA-component] Attachable - preview

Hi,

i created a cuba app-component that you can use. It is in preview mode currently. Before releasing it “officially” i would like to get your feedback on it. It is open source (Apache 2 license) and you can find it on github:

If you have any thoughts on that, like bug, feature requests etc. i would love to hear from you.

I’ll just copy over the README.md so you get an impression on what it does:

CUBA Platform Component - Attachable

This application component lets you easily add attachments to any entity in your application.

Just add @WithAttachments on the browse screen of your entity and the rest will be done by this app-component.

Usage

To add attachments to your entity, you have to add the following annotation to your browse / edit screen controller:

@WithAttachments(listComponent = "customersTable")
public class CustomerBrowse extends AnnotatableAbstractLookup {
}

For the @WithAttachments annotation you need to define the list component on which it should add the attachments button.
Normally this is the id of the table you defined in your browse screen.

This annotation will create a button in the buttonsPanel of the table and add the Attachments button after the default CUBA buttons.

The @WithAttachments annotations can be customized through the following attributes:

  • String listComponent - the id of the list component / table where the button will be added - REQUIRED
  • String buttonId - the id of the newly created button that will be created (“attachmentBtn” by default)
  • String buttonsPanel - the id of the buttons panel where the new button will be added (“buttonsPanel” by default)

Example usage

To see this application component in action, check out this example: cuba-example-using-attachable.

Attachment list

The attachment button will show all attachments that have been added to a particular selected entity.
It allows to add, edit & remove attachments to this entity.

Attachment preview

Furthermore it gives the user the option to preview the attachment directly in the browser or download the attachment.

The ability to do the preview depends on the attachment type and the browser capabilities.

Configuration options

The application components adds the following application properties, that can be changed in the corresponding screen (`Administration > Application Properties):

  • attachable.updateAttachmentCounterOnSelect - whether or not a counter of attachments should be displayed after a particular entity is selected in the table

Installation

NOTE: Dependency: declarative-controllers

This application component requires declarative-controllers as another dependency you have to add to your application.

The reason is, that you need to extend your screen from AnnotatableAbstractLookup instead of AbstractLookup.
This superclass is part of the app-component: cuba-component-declarative-controllers.

Technically it is not strictly required to directly add the dependency to declarative-controllers, since attachable already has a dependency on it.

However: since you directly depend on the app component (with extending your classes from AnnotatableAbstractLookup),
it is a best practice to explicitly declare the dependency to it.

  1. Add the following maven repository https://dl.bintray.com/mariodavid/cuba-components to the build.gradle of your CUBA application:

    buildscript {

     //...
     
     repositories {
     
         // ...
     
         maven {
             url  "https://dl.bintray.com/mariodavid/cuba-components"
         }
     }
     
     // ...
    

    }

  2. Select a version of the add-on which is compatible with the platform version used in your project:

Platform Version declarative-controllers Add-on Version
6.8.x 0.4.x 0.1.x

The latest version is: Download

Add custom application component to your project:

  • Artifact group: de.diedavids.cuba.attachable
  • Artifact name: attachable-global
  • Version: add-on version
  1. install the compatible version of cuba-component-declarative-controllers as another dependecy (see Table from 2. for version compatability).
8 Likes

Hi, Mario,
great work, man! I am particularly interested in the declarative controllers component in view of implementing functionality which can be described as “declarative component constraints”. I’d like to have a common mechanism to solve tasks like “if entity status is CLOSED you can change nothing” (a component should be disabled). It could be achieved easily for simple fields using Entity Attribute Access Control but this doesn’t work for collections when marking collections as read-only should lead to setting the corresponding table disable flag.

Regards,
Ilia.

Hi,

just wanted to let you know that 0.3.0 is out for usage. The following things were added:

Added

  • Possibility to add Tags to Attachments (#1)
  • Multi Upload for attachments (#3)
  • Drag & Drop while uploading files (#5)
  • bugfix for erasing name after file upload (#2)

Check it out: Service End for Bintray, JCenter, GoCenter, and ChartCenter | JFrog

1 Like

Attachable for @CubaPlatform is out in 0.4.0 with PostgreSQL support as well as Attachment Categories. Check it out: GitHub - mariodavid/cuba-component-attachable: CUBA component that lets you add attachments to any entity

1 Like

“attachable” application component for @CubaPlatform is released in version 0.5.1 with CUBA 6.10 support. Check it out:

giphy

Hi @mario

Trying to translate this addon to french I set the following lines in my main messages.properties

de.diedavids.cuba.attachable.web.attachment/multiupload = Charger…
de.diedavids.cuba.attachable.web.attachment/browseCaption = Attachment browser
de.diedavids.cuba.attachable.web.attachment/editorCaption = Attachment editor
de.diedavids.cuba.attachable.web.attachment/attachmentPreview=Attachment Preview
de.diedavids.cuba.attachable.web.attachment/actions.Download=
de.diedavids.cuba.attachable.web.attachment/actions.Preview=
de.diedavids.cuba.attachable.web.attachment/attachmentDownloaded= Attachment downloaded

It works for multiupload, but not for browseCaption & editorCaption. I suspect that CUBA prioritize messages files in the addon for this case.

Any advice ?

Regards
Michael

Please disregard previous post, for obvious reasons…

Hi,

Your example doesn’t work(see below):

Could not find de.diedavids.cuba.attachable:attachable-global:0.7.1-SNAPSHOT.
Searched in the following locations:
  - file:/C:/Users/.m2/repository/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/maven-metadata.xml
  - file:/C:/Users/.m2/repository/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/attachable-global-0.7.1-SNAPSHOT.pom
  - file:/C:/Users/.m2/repository/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/attachable-global-0.7.1-SNAPSHOT.jar
  - https://repo.cuba-platform.com/content/groups/work/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/maven-metadata.xml
  - https://repo.cuba-platform.com/content/groups/work/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/attachable-global-0.7.1-SNAPSHOT.pom
  - https://repo.cuba-platform.com/content/groups/work/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/attachable-global-0.7.1-SNAPSHOT.jar
  - https://dl.bintray.com/mariodavid/cuba-components/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/maven-metadata.xml
  - https://dl.bintray.com/mariodavid/cuba-components/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/attachable-global-0.7.1-SNAPSHOT.pom
  - https://dl.bintray.com/mariodavid/cuba-components/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/attachable-global-0.7.1-SNAPSHOT.jar
  - https://dl.bintray.com/balvi/cuba-components/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/maven-metadata.xml
  - https://dl.bintray.com/balvi/cuba-components/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/attachable-global-0.7.1-SNAPSHOT.pom
  - https://dl.bintray.com/balvi/cuba-components/de/diedavids/cuba/attachable/attachable-global/0.7.1-SNAPSHOT/attachable-global-0.7.1-SNAPSHOT.jar
Required by:
    project :

On the other hand when I tried to install it I have this error:

PSQLException: ERROR: relation "ddca_attachement" does not exist
  Position: 134

I had to update database in order to solve the issue.

Hi,

As you see in the error message, it says the version is not found. This is because 0.7.1-SNAPSHOT is not a released version. Probably it is becaused i used it locally when developing… but you can just switched to a released version: 0.7.0 / 0.8.0 in the build.gradle version of the example.

DB update is needed, correct :+1:
Cheers
Mario

FYI: I just updated the example to 0.8.0

If you re-download the example, everything should be fine… :slight_smile:

Cheers
Mario

Thank you Mario.
You did a great job.

Another short questions please:
I saw that if instead ofgroupTable I use a treeTable the buttonsPanel is not recognized and the app doesn’t work. Is there any workaround?

I saw that you modified database tables and added ddca_attachement, ddca_attachement_category etc
Where should I find the (update) sql command for all these tables: “create table…” I need this command, please in order to update an existing database.

Best Regards,
-n