Skip to content

Commit

Permalink
Add ng-gridstack library and move logics
Browse files Browse the repository at this point in the history
  • Loading branch information
hmtylmz committed Dec 24, 2019
1 parent 227144d commit c4a221f
Show file tree
Hide file tree
Showing 27 changed files with 272 additions and 65 deletions.
35 changes: 35 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,41 @@
}
}
}
},
"ng-gridstack": {
"projectType": "library",
"root": "projects/ng-gridstack",
"sourceRoot": "projects/ng-gridstack/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/ng-gridstack/tsconfig.lib.json",
"project": "projects/ng-gridstack/ng-package.json"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/ng-gridstack/src/test.ts",
"tsConfig": "projects/ng-gridstack/tsconfig.spec.json",
"karmaConfig": "projects/ng-gridstack/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/ng-gridstack/tsconfig.lib.json",
"projects/ng-gridstack/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}},
"defaultProject": "gridstack-angular"
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.8",
"@angular-devkit/build-ng-packagr": "~0.803.21",
"@angular/cli": "~8.3.8",
"@angular/compiler-cli": "~8.2.9",
"@angular/language-service": "~8.2.9",
Expand All @@ -46,8 +47,10 @@
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"ng-packagr": "^5.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tsickle": "^0.37.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3"
}
Expand Down
24 changes: 24 additions & 0 deletions projects/ng-gridstack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# NgGridstack

This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.2.14.

## Code scaffolding

Run `ng generate component component-name --project ng-gridstack` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ng-gridstack`.
> Note: Don't forget to add `--project ng-gridstack` or else it will be added to the default project in your `angular.json` file.
## Build

Run `ng build ng-gridstack` to build the project. The build artifacts will be stored in the `dist/` directory.

## Publishing

After building your library with `ng build ng-gridstack`, go to the dist folder `cd dist/ng-gridstack` and run `npm publish`.

## Running unit tests

Run `ng test ng-gridstack` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
32 changes: 32 additions & 0 deletions projects/ng-gridstack/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (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-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/ng-gridstack'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};
7 changes: 7 additions & 0 deletions projects/ng-gridstack/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/ng-gridstack",
"lib": {
"entryFile": "src/public-api.ts"
}
}
8 changes: 8 additions & 0 deletions projects/ng-gridstack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "ng-gridstack",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^8.2.14",
"@angular/core": "^8.2.14"
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { GridstackItemComponent } from './gridstack-item.component';
import { NgGridstackItemComponent } from './ng-gridstack-item.component';

describe('GridstackItemComponent', () => {
let component: GridstackItemComponent;
let fixture: ComponentFixture<GridstackItemComponent>;
describe('NgGridstackItemComponent', () => {
let component: NgGridstackItemComponent;
let fixture: ComponentFixture<NgGridstackItemComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ GridstackItemComponent ]
declarations: [ NgGridstackItemComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(GridstackItemComponent);
fixture = TestBed.createComponent(NgGridstackItemComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
/// <reference types="gridstack" />

import { Component, ChangeDetectionStrategy, Input, Renderer2, ElementRef, AfterViewInit, OnDestroy } from '@angular/core';
import { GridstackService } from '../gridstack.service';
import { NgGridstackService } from '../../services/ng-gridstack.service';

@Component({
selector: 'app-gridstack-item',
templateUrl: './gridstack-item.component.html',
styleUrls: ['./gridstack-item.component.scss'],
selector: 'ng-gridstack-item',
templateUrl: './ng-gridstack-item.component.html',
styleUrls: ['./ng-gridstack-item.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class GridstackItemComponent implements AfterViewInit, OnDestroy {
export class NgGridstackItemComponent implements AfterViewInit, OnDestroy {
@Input() id: string;

@Input() set x(value: number) {
Expand Down Expand Up @@ -67,7 +67,7 @@ export class GridstackItemComponent implements AfterViewInit, OnDestroy {
constructor(
private elementRef: ElementRef,
private renderer: Renderer2,
private gridstackService: GridstackService) {
private gridstackService: NgGridstackService) {
this.element = this.elementRef.nativeElement;
this.renderer.addClass(this.element, 'grid-stack-item');
this.renderer.setAttribute(this.element, 'data-gs-no-resize', false.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host(*) {
display: block;
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { GridstackComponent } from './gridstack.component';
import { NgGridstackComponent } from './ng-gridstack.component';

describe('GridstackComponent', () => {
let component: GridstackComponent;
let fixture: ComponentFixture<GridstackComponent>;
describe('NgGridstackComponent', () => {
let component: NgGridstackComponent;
let fixture: ComponentFixture<NgGridstackComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ GridstackComponent ]
declarations: [ NgGridstackComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(GridstackComponent);
fixture = TestBed.createComponent(NgGridstackComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import {
Component, ChangeDetectionStrategy, ElementRef, Input, ContentChildren, QueryList, Renderer2, OnInit, Output, EventEmitter
} from '@angular/core';
import { GridstackItemComponent } from '../gridstack-item/gridstack-item.component';
import { GridstackService } from '../gridstack.service';
import { NgGridstackItemComponent } from '../ng-gridstack-item/ng-gridstack-item.component';
import { NgGridstackService } from '../../services/ng-gridstack.service';

@Component({
selector: 'app-gridstack',
templateUrl: './gridstack.component.html',
styleUrls: ['./gridstack.component.scss'],
selector: 'ng-gridstack',
templateUrl: './ng-gridstack.component.html',
styleUrls: ['./ng-gridstack.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class GridstackComponent implements OnInit {
@ContentChildren(GridstackItemComponent) items: QueryList<GridstackItemComponent>;
export class NgGridstackComponent implements OnInit {
@ContentChildren(NgGridstackItemComponent) items: QueryList<NgGridstackItemComponent>;

@Input() options: GridstackOptions;
@Output() change = new EventEmitter<any>();
Expand All @@ -25,7 +25,7 @@ export class GridstackComponent implements OnInit {
constructor(
private elementRef: ElementRef,
private renderer: Renderer2,
private gridstackService: GridstackService) {
private gridstackService: NgGridstackService) {
this.element = this.elementRef.nativeElement;
this.renderer.addClass(this.element, 'grid-stack');
}
Expand Down
23 changes: 23 additions & 0 deletions projects/ng-gridstack/src/lib/ng-gridstack.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NgGridstackService } from './services/ng-gridstack.service';
import { NgGridstackItemComponent } from './components/ng-gridstack-item/ng-gridstack-item.component';
import { NgGridstackComponent } from './components/ng-gridstack/ng-gridstack.component';

@NgModule({
declarations: [
NgGridstackComponent,
NgGridstackItemComponent
],
imports: [
CommonModule
],
exports: [
NgGridstackComponent,
NgGridstackItemComponent
],
providers: [
NgGridstackService
]
})
export class NgGridstackModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
import { Injectable } from '@angular/core';

@Injectable()
export class GridstackService {
export class NgGridstackService {
grid: GridStack;
}
10 changes: 10 additions & 0 deletions projects/ng-gridstack/src/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Public API Surface of ng-gridstack
*/

export * from './lib/ng-gridstack.module';

// Components

export * from './lib/components/ng-gridstack/ng-gridstack.component';
export * from './lib/components/ng-gridstack-item/ng-gridstack-item.component';
21 changes: 21 additions & 0 deletions projects/ng-gridstack/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: any;

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
26 changes: 26 additions & 0 deletions projects/ng-gridstack/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
17 changes: 17 additions & 0 deletions projects/ng-gridstack/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
17 changes: 17 additions & 0 deletions projects/ng-gridstack/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"ng",
"camelCase"
],
"component-selector": [
true,
"element",
"ng",
"kebab-case"
]
}
}
8 changes: 4 additions & 4 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div>
<app-gridstack [options]="options">
<app-gridstack-item *ngFor="let item of items; index as index" [x]="item.x" [y]="item.y" [width]="item.width" [height]="item.height" [id]="item.id">
<ng-gridstack [options]="options">
<ng-gridstack-item *ngFor="let item of items; index as index" [x]="item.x" [y]="item.y" [width]="item.width" [height]="item.height" [id]="item.id">
Id: {{item.id}}
</app-gridstack-item>
</app-gridstack>
</ng-gridstack-item>
</ng-gridstack>
</div>
Loading

0 comments on commit c4a221f

Please sign in to comment.