Skip to content

Commit

Permalink
feat(message-box-dialog): first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Badisi committed Jun 26, 2024
1 parent ae7b7e9 commit 534d841
Show file tree
Hide file tree
Showing 25 changed files with 459 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- layout
- list-loader
- message-box
- message-box-dialog
- numeric-stepper
- overlay
- search-container
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci_test_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ jobs:
# needs: ci_test_core
# uses: ./.github/workflows/ci_test_layout.yml

ci_test_numeric_stepper:
ci_test_message-box-dialog:
needs: ci_test_core
uses: ./.github/workflows/ci_test_message-box-dialog.yml

ci_test_numeric-stepper:
needs: ci_test_core
uses: ./.github/workflows/ci_test_numeric-stepper.yml

Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/ci_test_message-box-dialog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test message-box-dialog

on:
workflow_dispatch:
workflow_call:
push:
branches:
- '**'
tags-ignore:
- '**'
paths:
- '.github/workflows/ci_test_message-box-dialog.yml'
- 'projects/message-box-dialog/**'

concurrency:
group: ci-test-message-box-dialog-group-${{ github.ref }}
cancel-in-progress: true

jobs:
ci_test_message-box-dialog:
if: "${{ !contains(github.event.head_commit.message, 'chore(release): publish') }}"
uses: dsi-hug/action/.github/workflows/action.yml@v1
with:
working-directory: projects/message-box-dialog
runs-on: '["ubuntu-latest", "macos-latest", "windows-latest"]'
node-versions: '[18, 20]'
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Package | Version | Downloads | Tests
[@hug/ngx-layout](/projects/layout) | [![npm version][npm-logo-layout]][npm-layout] | [![npm downloads][npm-dl-logo-layout]][npm-dl-layout] | [![build status][tests-logo-layout]][tests-layout]
[@hug/ngx-list-loader](/projects/list-loader) | [![npm version][npm-logo-list-loader]][npm-list-loader] | [![npm downloads][npm-dl-logo-list-loader]][npm-dl-list-loader] | [![build status][tests-logo-list-loader]][tests-list-loader]
[@hug/ngx-message-box](/projects/message-box) | [![npm version][npm-logo-message-box]][npm-message-box] | [![npm downloads][npm-dl-logo-message-box]][npm-dl-message-box] | [![build status][tests-logo-message-box]][tests-message-box]
[@hug/ngx-message-box-dialog](/projects/message-box-dialog) | [![npm version][npm-logo-message-box-dialog]][npm-message-box-dialog] | [![npm downloads][npm-dl-logo-message-box-dialog]][npm-dl-message-box-dialog] | [![build status][tests-logo-message-box-dialog]][tests-message-box-dialog]
[@hug/ngx-numeric-stepper](/projects/numeric-stepper) | [![npm version][npm-logo-numeric-stepper]][npm-numeric-stepper] | [![npm downloads][npm-dl-logo-numeric-stepper]][npm-dl-numeric-stepper] | [![build status][tests-logo-numeric-stepper]][tests-numeric-stepper]
[@hug/ngx-overlay](/projects/overlay) | [![npm version][npm-logo-overlay]][npm-overlay] | [![npm downloads][npm-dl-logo-overlay]][npm-dl-overlay] | [![build status][tests-logo-overlay]][tests-overlay]
[@hug/ngx-search-container](/projects/search-container) | [![npm version][npm-logo-search-container]][npm-search-container] | [![npm downloads][npm-dl-logo-search-container]][npm-dl-search-container] | [![build status][tests-logo-search-container]][tests-search-container]
Expand Down Expand Up @@ -107,6 +108,13 @@ Copyright (C) 2024 [HUG - Hôpitaux Universitaires Genève][dsi-hug]
[tests-message-box]: https://github.com/dsi-hug/ngx-components/actions/workflows/ci_test_message-box.yml
[tests-logo-message-box]: https://github.com/dsi-hug/ngx-components/actions/workflows/ci_test_message-box.yml/badge.svg

[npm-message-box-dialog]: https://www.npmjs.com/package/@hug/ngx-message-box-dialog
[npm-logo-message-box-dialog]: https://img.shields.io/npm/v/@hug/ngx-message-box-dialog.svg?color=blue&logo=npm
[npm-dl-message-box-dialog]: https://npmcharts.com/compare/@hug/ngx-message-box-dialog?minimal=true
[npm-dl-logo-message-box-dialog]: https://img.shields.io/npm/dw/@hug/ngx-message-box-dialog.svg?color=7986CB&logo=npm&label=npm
[tests-message-box-dialog]: https://github.com/dsi-hug/ngx-components/actions/workflows/ci_test_message-box-dialog.yml
[tests-logo-message-box-dialog]: https://github.com/dsi-hug/ngx-components/actions/workflows/ci_test_message-box-dialog.yml/badge.svg

[npm-numeric-stepper]: https://www.npmjs.com/package/@hug/ngx-numeric-stepper
[npm-logo-numeric-stepper]: https://img.shields.io/npm/v/@hug/ngx-numeric-stepper.svg?color=blue&logo=npm
[npm-dl-numeric-stepper]: https://npmcharts.com/compare/@hug/ngx-numeric-stepper?minimal=true
Expand Down
31 changes: 31 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,37 @@
}
}
}
},
"message-box-dialog": {
"projectType": "library",
"root": "projects/message-box-dialog",
"sourceRoot": "projects/message-box-dialog/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"project": "projects/message-box-dialog/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "projects/message-box-dialog/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "projects/message-box-dialog/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/message-box-dialog/src/test.ts",
"tsConfig": "projects/message-box-dialog/tsconfig.spec.json",
"karmaConfig": "projects/message-box-dialog/karma.conf.js"
}
}
}
}
}
}
21 changes: 20 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"projects/layout",
"projects/list-loader",
"projects/message-box",
"projects/message-box-dialog",
"projects/numeric-stepper",
"projects/overlay",
"projects/search-container",
Expand Down
6 changes: 6 additions & 0 deletions projects/message-box-dialog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@hug/message-box-dialog
=======

The sources for this package are in the main [DSI-HUG/ngx-components](https://github.com/dsi-hug/ngx-components) repo. Please file issues and pull requests against that repo.

License: GPL-3.0-only
45 changes: 45 additions & 0 deletions projects/message-box-dialog/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = config => {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, '../../coverage/message-box-dialog'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' }
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
failOnEmptyTestSuite: false,
restartOnFileChange: true
});
};
15 changes: 15 additions & 0 deletions projects/message-box-dialog/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/message-box-dialog",
"assets": [
"CHANGELOG.md",
{
"input": "src/",
"glob": "_message-box-dialog-theme.scss",
"output": "."
}
],
"lib": {
"entryFile": "src/index.ts"
}
}
45 changes: 45 additions & 0 deletions projects/message-box-dialog/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@hug/ngx-message-box-dialog",
"version": "1.0.0",
"description": "HUG Angular - message-box-dialog component",
"homepage": "https://github.com/dsi-hug/ngx-components",
"license": "GPL-3.0-only",
"author": "HUG - Hôpitaux Universitaires Genève",
"contributors": [
"badisi (https://github.com/badisi)",
"vapkse (https://github.com/vapkse)"
],
"repository": {
"type": "git",
"url": "git+https://github.com/dsi-hug/ngx-components.git"
},
"keywords": [
"angular",
"material",
"material design",
"components"
],
"sideEffects": false,
"scripts": {
"lint": "eslint . --fix",
"test": "ng test message-box-dialog",
"test:ci": "ng test message-box-dialog --watch=false --browsers=ChromeHeadless",
"build:ng": "ng build message-box-dialog -c=production",
"build": "nx build:ng @hug/ngx-message-box-dialog --verbose",
"release": "nx release -p=@hug/ngx-message-box-dialog --yes --verbose",
"release:dry-run": "nx release -p=@hug/ngx-message-box-dialog --verbose --dry-run"
},
"peerDependencies": {
"@angular/common": ">= 14",
"@angular/core": ">= 14",
"@angular/material": ">= 14",
"rxjs": ">= 7.0.0",
"@hug/ngx-core": "1.1.5"
},
"dependencies": {
"tslib": "^2.6.3"
},
"publishConfig": {
"access": "public"
}
}
33 changes: 33 additions & 0 deletions projects/message-box-dialog/src/_message-box-dialog-theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@use '@angular/material' as mat;

@mixin message-box-dialog-theme($theme) {
$warn: map-get($theme, warn);

.cdk-overlay-container {
.cdk-overlay-pane {
&.warning {
app-message-box-dialog {
.mat-toolbar {
background-color: mat.get-color-from-palette(mat.$orange-palette, 500);
}

button.mat-primary {
color: mat.get-color-from-palette(mat.$orange-palette, 500);
}
}
}

&.error {
app-message-box-dialog {
.mat-toolbar {
background-color: mat.get-color-from-palette($warn);
}

button.mat-primary {
color: mat.get-color-from-palette($warn);
}
}
}
}
}
}
4 changes: 4 additions & 0 deletions projects/message-box-dialog/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './message-box-dialog.component';
export * from './message-box-dialog.service';
export * from './message-box-dialog.model';
export * from './message-box-dialog.module';
18 changes: 18 additions & 0 deletions projects/message-box-dialog/src/message-box-dialog.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<mat-toolbar class="dialog-toolbar" color="primary">
<span class="dialog-title" data-cy="confirmation-dialog-title">{{ dialogParams.title }}</span>
<mat-icon class="dialog-action" mat-dialog-close="cancel">close</mat-icon>
</mat-toolbar>

<div class="dialog-container">
<div [innerHTML]="dialogParams.text"></div>
</div>

<div class="dialog-buttons">
<button type="button" id="cancelbtn" mat-button mat-dialog-close="cancel" *ngIf="hasControl('CANCEL')" color="primary" data-cy="cancel">Annuler</button>
<button type="button" mat-button mat-dialog-close="ignore" *ngIf="hasControl('IGNORE')" color="primary" data-cy="ignore">Ignorer</button>
<button type="button" mat-stroked-button default mat-dialog-close="retry" *ngIf="hasControl('RETRY')" color="primary" data-cy="retry">Recommencer</button>
<button type="button" id="okbtn" mat-stroked-button mat-dialog-close="ok" *ngIf="hasControl('OK')" color="primary" data-cy="ok">Ok</button>
<button type="button" mat-stroked-button mat-dialog-close="yes" *ngIf="hasControl('YES')" color="primary" data-cy="yes">Oui</button>
<button type="button" mat-stroked-button mat-dialog-close="no" *ngIf="hasControl('NO')" color="primary" data-cy="no">Non</button>
<button type="button" mat-stroked-button mat-dialog-close="continue" *ngIf="hasControl('CONTINUE')" color="primary" data-cy="continue">Continuer</button>
</div>
10 changes: 10 additions & 0 deletions projects/message-box-dialog/src/message-box-dialog.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
app-message-box-dialog {
padding-top: 1rem;

.dialog-container {
display: flex;
flex-direction: column;
margin: 1rem 1rem 0.5rem 1rem;
max-height: 80vh;
}
}
22 changes: 22 additions & 0 deletions projects/message-box-dialog/src/message-box-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ChangeDetectionStrategy, Component, Inject, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';

import { MessageBoxDialogButtons, MessageBoxDialogData } from './message-box-dialog.model';

@Component({
selector: 'app-message-box-dialog',
templateUrl: './message-box-dialog.component.html',
styleUrls: ['./message-box-dialog.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
})
export class MessageBoxDialogComponent {
public constructor(
@Inject(MAT_DIALOG_DATA) protected dialogParams: MessageBoxDialogData
) { }

protected hasControl(key: 'OK' | 'CANCEL' | 'IGNORE' | 'RETRY' | 'YES' | 'NO' | 'CONTINUE'): boolean {
// eslint-disable-next-line no-bitwise
return !!this.dialogParams.buttons && (this.dialogParams.buttons & MessageBoxDialogButtons[key]) !== 0;
}
}
17 changes: 17 additions & 0 deletions projects/message-box-dialog/src/message-box-dialog.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export type MessageBoxDialogResponse = 'ok' | 'cancel' | 'ignore' | 'retry' | 'yes' | 'no' | 'continue';

export enum MessageBoxDialogButtons {
OK = 0x1,
CANCEL = 0x2,
IGNORE = 0x4,
RETRY = 0x8,
YES = 0x10,
NO = 0x20,
CONTINUE = 0x40
}

export interface MessageBoxDialogData {
title: string;
text: string;
buttons?: MessageBoxDialogButtons;
}
Loading

0 comments on commit 534d841

Please sign in to comment.