npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

uica-widgets

v1.0.0-beta.2

Published

User Interface Component Architecture Widgets

Downloads

39

Readme

uica-widgets

User Interface Component Architecture (UICA) Widgets

How to use the table widget

General

If a component should be a table then it is necessary that this component extends from the abstract table widget component:

    extend: app.widget.abstract.table.{ctrl|model|view}

If the table should be able to support single select and/or multi select and/or tree functionality it is necessary to overwrite the specific mehtods. e.g. for single select

   singleSelectPluginOptions () {
        let selectOptions = this.singleSelectDefaultOptions()
        selectOptions.markups = {
            checkedMarkup: this.view.call("jbit7:multiSelectCheckedMarkup"),
            uncheckedMarkup: this.view.call("jbit7:multiSelectUncheckedMarkup")
        }
        return selectOptions
    },

   singleSelectDefaultOptions () {
        return {
            width: 30,
            minWidth: 30,
            cssClass: "{specific CSS-Class}",
            headerCssClass: "{specific CSS-Class}"
        }
    },

For multi select please overwrite the methods multiSelectPluginOptions and multiSelectDefaultOptions and for the tree functionality the methods treePluginOptions and treeDefaultOptions have to be overwritten.

How to initialize the table

Options

Setting the options is done in the model. Except the default options of the library SlickGrid, the following default oprions are set:

If it is necessary to have different options than the default, they can be overwritten in the method initializeOptions in the model, e.g.

	initializeOptions () {
        this.base()
        this.options.multiSelect = true
        this.options.editable = true
		this.options.rowHeight = 36
    }

Columns

To define which columns should exist for the table, it is necessary to implement the method initializeColumns. The method must set the dynamics columns, it must be an array of column object. A column object hast the following mandatory and optional fields (see also SlickGrid Column-Options):

An example for the method initializeColumns:

initializeColumns () {
        let columns = [
            {id: "type", cssClass: "centerText",  headerCssClass: "centerText", maxWidth: 200, 
				formatter: app.util.format.slickColumnFormatter.typeFormatter},
            {id: "origin", cssClass: "centerText",  headerCssClass: "centerText", maxWidth: 200},
            {id: "description", cssClass: "centerText",  headerCssClass: "centerText"}
        ]

        this.columns = _.map(columns, each => {
            each.field = each.field || each.id
            each.name = each.name || i18next.t(`___config.id___.column.${each.id}`)
            each.toolTip = each.toolTip || i18next.t(`___config.id___.tooltip.${each.id}`)
            each.sortable = each.hasOwnProperty('sortable') ? each.sortable : true
            each.useFormatterForSearch = each.hasOwnProperty('useFormatterForSearch') ? each.useFormatterForSearch: true
            each.useFormatterForSort = each.hasOwnProperty('useFormatterForSort') ? each.useFormatterForSort: true
            return each
        })
    }

Data Table Entries

Setting the data is done in the controller. In the observer of the data it is necessary to call teh method updatePresentationTableEntries, e.g.:

  this.observeParentModel("global:data:orders", (ev, orders, oldOrders) => {
  		this.updatePresentationTableEntries(orders, oldOrders)
  }, {boot: true})

The method updatePresentationTableEntries generates presentation objects out of the given data objects, that will be given to the table.

If it is necessary that the presentation object has more or different attributes then the data object, it is possible to add or overwrite attributes in the method addPresentationAttributesToItemFromEntity, e.g.

	addPresentationAttributesToItemFromEntity (item, entity) {
        item.lossType = app.util.format.DisplayFormatter.lossTypeFormatter(entity)
        item.workorderState = entity.workOrder && entity.workOrder.postBoxState ? entity.workOrder.postBoxState.text : ""
    }

This method is internal called for each object of the array (in this example the array this.model.value("global:data:orders")) whereby the parameter item the generated presentation object is and entity the original data object. But it is not allowed to overwrite the attribute id in this method. Use the method presentationIdOfEntity instead.

The table needs a unique id, this is generated internal, by default the attribute id of the data object is used. If another id is needed, if the unique identifier of the data object is no the attribute id or even more than one attributes it is possible to overwrite the method presentationIdOfEntity (entity). This method needs to return the value of the unique identifier of the given data object (parameter entity).

	presentationIdOfEntity (entity) {
        return entity.orderId + entity.anotherAttribute
    }

TreeTable

For tree tables thie method generatePresentationTableEntries must be overwritten. To generate one table tree item call generatePresentationTreeEntry(entity, pParent, isLeaf, defaultCollapsed). If more attributes are needed for the tree table presentation object it is handle like with flat tables, the attributes needs to be added or overwritten for each table presentation object (item) in the method addPresentationAttributesToItemFromEntity.

Filter table entries

If there is a modelfield that holds the filter value, you can observe this modelfield and then call the method filterTableEntries with the filter value as parameter, e.g.

		this.observeParentModel("global:data:filterValue", (ev, value) => {
            this.filterTableEntries(value)
        }, {boot: true})

Sort table entries

It is possible to set the inital sort object. Normally this has to be done in the lifecycle create like this:

	    this.model.value("data:sortObject", {field: "{attribute of the presentation object}", asc: 1})

Sorting only possible if the Grid Option sortable is set to true.

Add, delete or update of a data object

The table were given presentation objects of data objects. It is possible that the array of data objects changes. Now the presentation objects or rather the table entries needs to be synchronized. Therefore the following needs to be done.

Add a new data object

The method addEntities(entities) can be called to add one or more entities (the parameter entities can be one single data object or an array o data objects).

Additional the method onItemAdded(args) must be overwritten. There the modelfield that holds the data objects must be updated.

	// args = {item: tableEntry, index: index}
	onItemAdded(args) {
        let addedEntity = args.item.entity
        this.model.value('global:data:orders').push(addedEntity)
    }

Delete an existing data object

The method addEntities(entities) can be called to delete one or more entities (the parameter entities can be one single data object or an array o data objects).

Additional the method onItemDeleted(args) must be overwritten. There the modelfield that holds the data objects must be updated.

	// args = {item: tableEntry}
	onItemDeleted(args) {
        let deletedEntity = args.item.entity
        _.remove(this.model.value('global:data:orders'), deletedEntity)
    }

Update a data object

The method updateEntities(entities) can be called to update one or more entities (the parameter entities can be one single data object or an array o data objects).

Additional the method onItemUpdated(args) ( args = {item: tableEntry, index: index} ) has to be overwritten if necessary. It is possible that this is not necessary when the references of the updated entitites was change before and due this change the update of the presentation objects was triggered.