Giter Site home page Giter Site logo

Comments (5)

genthalili avatar genthalili commented on May 27, 2024

I think using the global action logic as-is for Tables, GroupTable etc.. List of actions in CUBA would be a good direction.

A global ImportDataAction like ExcelAction or CreateAction would be the best solution.
Ideally this Action will be easy to implement for component users (devlopers):

<!-- actions -->
<action id="importData" directImport="true" />
...
<!-- buttonsPanel -->
<upload id="importFileUploadBtn" action="mytable.importData" uploadButtonIcon="icons/upload.png"/>
once the file selected and uploaded ...
if directImport == true 
**then** will force the upload process by searching for a configuration inside database related to that entity; auto-selecting one and following the process with the import
**else** will show a popup asking the user to select a configuration or create a new one (similar to step2 & step3 of the Wizard)
**exceptions** : Any exception will throw a message to the user

@mariodavid , Do you know if it's possible to create a global Action, and register it to the app? Exactly the same question asked by : https://www.cuba-platform.com/discuss/t/define-global-table-actions/894

Unfortunately today I have to write the code below on almost all my Browses:

class MyEntityBrowse2 extends EntityCombinedScreen {

    @Inject
    FileUploadField importFileUploadBtn

    @Inject
    FileUploadingAPI fileUploadingAPI

    ImportFileHandler importFileHandler

    ImportFileParser importFileParser

    @Inject
    DataConverterFactory dataConverterFactory

    @Inject
    DataManager dataManager

    @Inject
    GenericDataImporterService genericDataImporterService

    ImportData importData

    @Inject
    Metadata metadata

    @Inject
    Datasource<RouteMgmtType> routeMgmtTypeDs

    @Inject
    GroupDatasource<RouteMgmtType, UUID> routeMgmtTypesDs;

    @Override
    void init(Map<String, Object> params) {


        importFileHandler = new ImportFileHandler(
                importFileUploadBtn: importFileUploadBtn,
                fileUploadingAPI: fileUploadingAPI,
                dataManager: dataManager
        )

        importFileParser = new ImportFileParser(
                importFileHandler: importFileHandler,
                dataConverterFactory: dataConverterFactory
        )

        importFileHandler.onUploadSuccess {

            this.importData = importFileParser.parseFile();


            def iConfig = metadata.create(ImportConfiguration)
            iConfig.dateFormat = 'dd/MM/yyyy'
            iConfig.booleanTrueValue = 'Yes'
            iConfig.booleanFalseValue = 'No'
            iConfig.entityClass = routeMgmtTypeDs.metaClass.name
            iConfig.importAttributeMappers = [new ImportAttributeMapper(
                    configuration: iConfig,
                    entityAttribute: 'objectName',
                    fileColumnNumber: 0,
                    fileColumnAlias: 'objectName'
            )]

            def dataImportResult = genericDataImporterService.doDataImport(iConfig, importData)

            showNotification(String.format("Successfully imported %d records", dataImportResult.entitiesImportSuccess), NotificationType.TRAY_HTML);
            routeMgmtTypesDs.refresh();
        }
        importFileHandler.onUploadError {
            showNotification(formatMessage('fileUploadError'), Frame.NotificationType.ERROR)
        }

    }
}

from cuba-component-data-import.

mariodavid avatar mariodavid commented on May 27, 2024

As far as I know the using the same way the standard actions are defined is not easily possible.

But that does not really matter.
Joerg created this app component in response to this thread you mentioned: https://github.com/balvi/cuba-component-declarative-controllers

Which will solve the problem even more elegant.

from cuba-component-data-import.

genthalili avatar genthalili commented on May 27, 2024

Hi @mariodavid,
The component declarative-controllers is really great, but I'm struggling to make it working on the app: https://github.com/genthalili/cuba-component-data-import/tree/with-import-action-on-browser

https://github.com/genthalili/cuba-component-data-import/tree/with-import-action-on-browser/modules/web/src/de/diedavids/cuba/dataimport/web/importable

Do you know why @Component is never detected by cuba ?

from cuba-component-data-import.

genthalili avatar genthalili commented on May 27, 2024

never mind, I found the issue. I see that you already implemented the code, so that's even better

from cuba-component-data-import.

mariodavid avatar mariodavid commented on May 27, 2024

done in #76

from cuba-component-data-import.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.