Giter Site home page Giter Site logo

francescoborzi / ngx-duration-picker Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 9.0 2.45 MB

Angular component for ISO_8601 durations

Home Page: https://francescoborzi.github.io/ngx-duration-picker/index.html

License: MIT License

TypeScript 79.21% JavaScript 2.86% HTML 15.45% SCSS 2.48%
angular duration-picker iso8601 component

ngx-duration-picker's Introduction

Build Status npm version dependencies Status devDependencies Status License: MIT

ngx-duration-picker

ngx-duration-picker screenshot

A reusable Angular duration-picker component that works with ISO_8601 durations.

Requires Bootstrap, css only (no Bootstrap JS or jQuery needed).

Live demo

You can check a live demo of this library and all its features here

Installation

  • Run:

npm install --save ngx-duration-picker

  • Then in your app.module.ts add DurationPickerModule between your imports:
@NgModule({
  declarations: [...],
  imports: [
    DurationPickerModule,
    ...
  ],
  providers: [...],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage

<ngx-duration-picker [(value)]="myDuration"></ngx-duration-picker>

where myDuration will be the variable where the output is stored, you can also pass an initial value.

Watch for changes

if you need to perform some operations each time the bound variable changes, you can use (valueChange):

<ngx-duration-picker [(value)]="myDuration" (valueChange)="doSomeStuff()">

Passing options

you can pass specify some options by binding [options] to your configuration object:

<ngx-duration-picker [(value)]="myDuration" [options]="{ showWeeks: false }">

Available options

zeroValue

String or Null, default 'PT0S'.

Value to be used when the duration is 0. Since the specification says that 'PT0S' or 'P0D' are both valid, you are allowed to change this value. You can also pass just null.

showNegative

Boolean, default false. Sets up the option for negative and positive durations.

showButtons

Boolean, default true. Shows the up and down buttons.

showPreview

Boolean, default true. Shows a preview of the value.

previewFormat

String, default ISO.

You can optionally specify a date format using:

  • {{Y}} for years
  • {{M}} for months
  • {{W}} for weeks
  • {{D}} for days
  • {{h}} for hours
  • {{m}} for minutes
  • {{s}} for seconds

Example string: {{h}} hours : {{m}} minutes : {{s}} seconds

customOutputFormat

String, default ISO.

You can optionally specify:

  • timestamp for duration in milliseconds
  • seconds for duration in seconds
  • custom string as described in previewFormat option

Chosen value will be emitted by customOutput.

showLetters

Boolean, default true. Shows the letters on top (Y, M, W, D, H, M, S)

labels

Object, accepting labels that should be shown above the fields instead of default letters (showLetters has to be set to true).

Available fields (with default labels):

  • years (Y)
  • months (M)
  • weeks (W)
  • days (D)
  • hours (H)
  • minutes (M)
  • seconds (S)

Example object which is overwriting weeks and hours properties:

{
    weeks: 'tyg',
    hours: 'godz'
}

unitSteps

Object, accepting numbers representing increment/decrement step size for each unit. Non-positive values will be replaced with default value: 1.

Available fields:

  • years
  • months
  • weeks
  • days
  • hours
  • minutes
  • seconds

Example object which is overwriting weeks and hours properties:

{
    weeks: 4,
    hours: 2
}

showYears

Boolean, default true. Shows the years, when hidden it will be always considered as 0.

showMonths

Boolean, default true. Shows the months, when hidden it will be always considered as 0.

showWeeks

Boolean, default true. Shows the weeks, when hidden it will be always considered as 0.

showDays

Boolean, default true. Shows the days, when hidden it will be always considered as 0.

showHours

Boolean, default true. Shows the hours, when hidden it will be always considered as 0.

showMinutes

Boolean, default true. Shows the minutes, when hidden it will be always considered as 0.

showSeconds

Boolean, default true. Shows the seconds, when hidden it will be always considered as 0.

Local development

Run the application

  • On one terminal tab run ng build ngx-duration-picker --watch. This will build the library sources (projects/ngx-duration-picker/*) and watch for changes.

  • On another terminal tab run ng serve to serve the demo app (src/*) and play with it.

Run the tests

  • Unit tests are located in projects/ngx-duration-picker/src/lib/*.spec.ts and you can run them using npm run test:unit
  • Integration tests are located in src/app/integration-tests/*.spec.ts and you can run them using npm run test:integration

The default browser is Chrome. You can also append :ci to run them in Headless mode, and :ci:firefox to run them with Firefox.

Update Demo website (GitHub pages)

  • Run npm run build:demo and commit the docs/ directory

Donate

You can support me with a donation.

ngx-duration-picker's People

Contributors

angular-cli avatar dependabot[bot] avatar derhahne avatar francescoborzi avatar ppesr avatar renovate-bot avatar renovate[bot] avatar superdyzio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ngx-duration-picker's Issues

Error while trying to use `previewFormat` with AOT

The package has successfully installed and is perfectly running but when i try to add previewFormat in the options i get below error

core.js:4197 ERROR Error: Angular JIT compilation failed: '@angular/compiler' not loaded!

  • JIT compilation is discouraged for production use-cases! Consider AOT mode instead.
  • Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?
  • Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping.
    at getCompilerFacade (core.js:562)
    at Function.get (core.js:26205)
    at getComponentDef (core.js:1826)
    at extractDirectiveDef (core.js:1650)
    at Array.map ()
    at def.directiveDefs (core.js:1633)
    at createTView (core.js:7406)
    at getOrCreateTComponentView (core.js:7355)
    at createRootComponentView (core.js:13413)
    at ComponentFactory$1.create (core.js:22149)

My Code looks like below

    <ngx-duration-picker
          formControlName="period"
          [options]="{ previewFormat: '{{ H }}', customOutputFormat: 'H', showMonths: false, showSeconds: false, showYears: false, showWeeks: false }"></ngx-duration-picker>

Preview format

I understand that current format is a default, ISO-consistent format, but it would be nice to have possibility to pass some text (probably translatable) as preview, so it can show labels like

5 hours 0 minutes 15 seconds

Thanks for that lib, regards!

Output format

Currently only possible output format is default ISO. It would be nice to be able to configure that and get number or custom string as output.
It can go even further and since duration picker default use is to determine duration of some event / annotation etc. it would be great to pass startTime to ngx-duration-picker and get endTime as Date or moment object.

I'll try to work on that later.

LICENSE file

Could you please add LICENSE file? I can see here that license is MIT, but such a file is sometimes needed for formal verification of libraries used in project. I can submit PR if you don't have time for that.

Thanks for that lib, regards!

How to set max input value?

Here I attached the code snippets of project, I am using only minutes in my project. I want to set max value of the picker to be 999 and min value to 0.

@FrancescoBorzi can you help to guide how can I set this?

<ngx-duration-picker [(value)]="timeToHome" [options]="durationPickerOptions" required></ngx-duration-picker>

durationPickerOptions : any = {
        showPreview: false,
        showNegative: false,
        showLetters: false,
        showYears: false,
        showMonths: false,
        showWeeks: false,
        showDays: false,
        showHours: false,
        showSeconds: false,
    };

StaticInjectorError

Hi,

I just tried this component in my project but when I try it I get the following error:

ERROR Error: StaticInjectorError(MystaffAppModule)[NgIf -> ViewContainerRef]: 
  StaticInjectorError(Platform: core)[NgIf -> ViewContainerRef]: 
    NullInjectorError: No provider for ViewContainerRef!

Apprently the error is here:

      <tr *ngIf="config.showLetters">     <<===== Error
        <td *ngIf="config.showNegative"></td>
        <td *ngIf="config.showYears">Y</td>
        <td *ngIf="config.showMonths">M</td>
        <td *ngIf="config.showWeeks">W</td>
        <td *ngIf="config.showDays">D</td>
        <td *ngIf="config.showHours">H</td>
        <td *ngIf="config.showMinutes">M</td>
        <td *ngIf="config.showSeconds">S</td>
      </tr>

Numeric input/output

We store durations on our APIs in terms of seconds/minutes/etc and not ISO durations. It would be nice if the component would allow something like "seconds in, seconds out". Example:

<app-duration-picker [(ngModel)]="durationInSeconds" type="seconds/ISO/minutes/etc"></app-duration-picker>

Also, it would be nice to change the prefix of this project from app-duration-picker to something like ngx-duration-picker to avoid confusion with first and third party components.

error after updating to Angular 9

ngx-duration-picker version: 3.3.1

ERROR in node_modules/ngx-duration-picker/lib/duration-picker.component.d.ts:60:21 - error TS2694: Namespace '"/home/chris/Desktop/current/Clients/WebUI9/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDeclaration'.

I usually see this type of error because of a package version mismatch with the Angular version. But I can't seem to find the correct version for ngx-duration-picker

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm tslint Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency karma-jasmine to v4.0.2
  • chore(deps): update dependency jasmine-core to v3.99.1
  • chore(deps): update dependency karma-chrome-launcher to v3.2.0
  • chore(deps): update dependency ts-node to v10.9.2
  • fix(deps): update dependency tslib to v2.6.3
  • chore(deps): update actions/cache action to v4
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency @types/jasmine to v5
  • chore(deps): update dependency @types/node to v20
  • chore(deps): update dependency jasmine-core to v5
  • chore(deps): update dependency karma-jasmine to v5
  • chore(deps): update dependency karma-jasmine-html-reporter to v2
  • chore(deps): update dependency ng-packagr to v18
  • chore(deps): update dependency typescript to v5
  • chore(deps): update nick-invision/retry action to v3
  • 🔐 Create all rate-limited PRs at once 🔐

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/main.yml
  • actions/checkout v2
  • actions/setup-node v2
  • actions/cache v2
  • nick-invision/retry v2
  • nick-invision/retry v2
  • nick-invision/retry v2
  • nick-invision/retry v2
npm
package.json
  • @angular/animations 12.2.11
  • @angular/common 12.2.11
  • @angular/compiler 12.2.11
  • @angular/core 12.2.11
  • @angular/forms 12.2.11
  • @angular/platform-browser 12.2.11
  • @angular/platform-browser-dynamic 12.2.11
  • @angular/router 12.2.11
  • rxjs 6.6.7
  • tslib 2.3.1
  • zone.js 0.11.4
  • @angular-devkit/build-angular 12.2.18
  • @angular-devkit/core 12.2.18
  • @angular/cli 12.2.18
  • @angular/compiler-cli 12.2.11
  • @angular/language-service 12.2.11
  • @types/jasmine 3.10.1
  • @types/jasminewd2 2.0.10
  • @types/node 14.18.48
  • bootstrap 4.6.2
  • codelyzer 6.0.2
  • jasmine-core 3.10.1
  • jasmine-spec-reporter 7.0.0
  • karma 6.3.6
  • karma-chrome-launcher 3.1.0
  • karma-coverage-istanbul-reporter 3.0.3
  • karma-firefox-launcher 2.1.1
  • karma-jasmine 4.0.1
  • karma-jasmine-html-reporter 1.7.0
  • ng-packagr 12.2.4
  • ts-node 10.4.0
  • tslint 6.1.3
  • typescript 4.3.5
projects/ngx-duration-picker/package.json
  • tslib 2.3.1
  • @angular/common *
  • @angular/core *

  • Check this box to trigger a request for Renovate to run again on this repository

Only allow numbers as input

The widgets currently allow entering chars as input. According to the input widget this doesn't make sense and seems to result in a null value for the duration.

Maybe it is possible to restrict the user input to numbers to increase the user experience.

Configurable labels with units

Currently there is option to show letters above unit controls but it would be nice to be able to put there some custom labels.

I'll work on that later.

Add negative duration

It would be nice to allow negative timeshift. At leaste the ISO8601 allows a negative notation.

Step increment / decrement for each time unit

It would be nice to provide the component with step value on each time unit increment / decrement.
For example, in options, pass:
options = {
...,
hourStep: 10,
minuteStep: 5,
...
}

So, when the user click on Up / Down arrows,
update the time unit value according to time step value

Value set to 0

It want to be able to set the duration to 0 (PT0S)
I set all values in the widget to 0.
Expected behaviour: Value is set to PT0S or PT0D...
Current behavior: Value is set to null.

Possibility to disable duration picker control

Is it possible to disable the control? We have an issue that only an user with a special role is able to change the duration. So, if the user does not have the right permission it must be possible to make the control readonly.

One solution is to render only a Tag when the permission is not give but maybe it can although be possible to disable the control.

The labels are not working

Hi,
You have a cool package but the labels are not working...
image

I suppose that the unitSteps are not working either: take a look at augury's config on your component: ( Not all the config are there... )
image

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.