Skip to content

Commit

Permalink
chore(formatting): formatted lib
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Mar 30, 2018
1 parent c775b41 commit 82e10c4
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 191 deletions.
24 changes: 16 additions & 8 deletions libs/angular-star-rating/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// interfaces
export {ClickEvent} from './src/interfaces/click-event.interface';
export {HoverRatingChangeEvent} from './src/interfaces/hover-rating-change-event.interface';
export {RatingChangeEvent} from './src/interfaces/rating-change-event.interface';
export {StarRatingConfig} from './src/interfaces/star-rating-config.interface';
export { ClickEvent } from './src/interfaces/click-event.interface';
export {
HoverRatingChangeEvent
} from './src/interfaces/hover-rating-change-event.interface';
export {
RatingChangeEvent
} from './src/interfaces/rating-change-event.interface';
export {
StarRatingConfig
} from './src/interfaces/star-rating-config.interface';
// services
export {StarRatingUtils} from './src/services/star-rating.utils';
export {StarRating} from './src/services/star-rating';
export {StarRatingConfigService} from './src/services/star-rating-config.service';
export { StarRatingUtils } from './src/services/star-rating.utils';
export { StarRating } from './src/services/star-rating';
export {
StarRatingConfigService
} from './src/services/star-rating-config.service';
// components
export {StarRatingComponent} from './src/components/star-rating.component';
export { StarRatingComponent } from './src/components/star-rating.component';
// module
export { StarRatingModule } from './src/angular-star-rating.module';
18 changes: 8 additions & 10 deletions libs/angular-star-rating/src/angular-star-rating.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CommonModule} from '@angular/common';
import {ModuleWithProviders, NgModule} from '@angular/core';
import {StarRatingComponent} from './components/star-rating.component';
import {StarRatingConfigService} from './services/star-rating-config.service';
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { StarRatingComponent } from './components/star-rating.component';
import { StarRatingConfigService } from './services/star-rating-config.service';

const DECLARATIONS = [StarRatingComponent];
const EXPORTS = [DECLARATIONS];
Expand All @@ -15,16 +15,14 @@ export class StarRatingModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: StarRatingModule,
providers: [
StarRatingConfigService
]
}
providers: [StarRatingConfigService]
};
}

static forChild(): ModuleWithProviders {
static forChild(): ModuleWithProviders {
return {
ngModule: StarRatingModule,
providers: []
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ describe('StarRatingComponent', () => {
let component: StarRatingComponent;
let fixture: ComponentFixture<StarRatingComponent>;

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

beforeEach(() => {
fixture = TestBed.createComponent(StarRatingComponent);
Expand Down
95 changes: 46 additions & 49 deletions libs/angular-star-rating/src/components/star-rating.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Component, EventEmitter, forwardRef, Input} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
import {ClickEvent} from '../interfaces/click-event.interface';
import {HoverRatingChangeEvent} from '../interfaces/hover-rating-change-event.interface';
import {RatingChangeEvent} from '../interfaces/rating-change-event.interface';
import {StarRating} from '../services/star-rating';
import {StarRatingConfigService} from '../services/star-rating-config.service';
import {StarRatingUtils} from '../services/star-rating.utils';
import { Component, EventEmitter, forwardRef, Input } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { ClickEvent } from '../interfaces/click-event.interface';
import { HoverRatingChangeEvent } from '../interfaces/hover-rating-change-event.interface';
import { RatingChangeEvent } from '../interfaces/rating-change-event.interface';
import { StarRating } from '../services/star-rating';
import { StarRatingConfigService } from '../services/star-rating-config.service';
import { StarRatingUtils } from '../services/star-rating.utils';

const STAR_RATING_CONTROL_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
Expand All @@ -17,36 +17,32 @@ const STAR_RATING_CONTROL_ACCESSOR = {
selector: 'star-rating-comp',
providers: [STAR_RATING_CONTROL_ACCESSOR],
inputs: [
'getHalfStarVisible'
, 'getColor'
, 'showHalfStars'
, 'hoverEnabled'
, 'rating'
, 'step'
, 'disabled'
, 'readOnly'
, 'space'
, 'starType'
, 'size'
, 'speed'
, 'numOfStars'
, 'direction'
, 'staticColor'
'getHalfStarVisible',
'getColor',
'showHalfStars',
'hoverEnabled',
'rating',
'step',
'disabled',
'readOnly',
'space',
'starType',
'size',
'speed',
'numOfStars',
'direction',
'staticColor',
//, 'labelVisible'
, 'labelPosition'
, 'labelText'
, 'id'
],
outputs: [
'clickEmitter'
, 'ratingChangeEmitter'
, 'hoverRatingChangeEmitter'
'labelPosition',
'labelText',
'id'
],
outputs: ['clickEmitter', 'ratingChangeEmitter', 'hoverRatingChangeEmitter'],
styleUrls: [],
templateUrl: 'star-rating.component.html'
})
export class StarRatingComponent extends StarRating implements ControlValueAccessor {

export class StarRatingComponent extends StarRating
implements ControlValueAccessor {
//Outputs
///////////////////////////////////////////////////////////////////////////////////////////

Expand All @@ -58,15 +54,19 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces
}
}

ratingChangeEmitter: EventEmitter<RatingChangeEvent> = new EventEmitter<RatingChangeEvent>();
ratingChangeEmitter: EventEmitter<RatingChangeEvent> = new EventEmitter<
RatingChangeEvent
>();

saveOnRatingChange($event: RatingChangeEvent) {
if (this.ratingChangeEmitter) {
this.ratingChangeEmitter.emit($event);
}
}

hoverRatingChangeEmitter: EventEmitter<HoverRatingChangeEvent> = new EventEmitter<HoverRatingChangeEvent>();
hoverRatingChangeEmitter: EventEmitter<
HoverRatingChangeEvent
> = new EventEmitter<HoverRatingChangeEvent>();

saveOnHover($event: HoverRatingChangeEvent) {
if (this.hoverRatingChangeEmitter) {
Expand Down Expand Up @@ -95,7 +95,6 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces

//Keyboard events
onKeyDown(event: KeyboardEvent) {

if (!this.interactionPossible()) {
return;
}
Expand All @@ -118,12 +117,17 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces
};

const handleDigits = (eventCode: string): void => {
let dStr = "Digit";
let digit: number = parseInt(eventCode.substr(dStr.length, eventCode.length - 1));
let dStr = 'Digit';
let digit: number = parseInt(
eventCode.substr(dStr.length, eventCode.length - 1)
);
this.rating = digit;
};

if (handlers[event['code']] || StarRatingUtils.isDigitKeyEventCode(event['code'])) {
if (
handlers[event['code']] ||
StarRatingUtils.isDigitKeyEventCode(event['code'])
) {
if (StarRatingUtils.isDigitKeyEventCode(event['code'])) {
handleDigits(event['code']);
} else {
Expand Down Expand Up @@ -153,18 +157,15 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces

//Hover events
onStarHover(rating?: number): void {

if (!this.interactionPossible() || !this.hoverEnabled) {
return;
}

this.hoverRating = rating ? parseInt(rating.toString()) : 0;

//fire onHoverRatingChange event
let $event: HoverRatingChangeEvent = {hoverRating: this.hoverRating};
let $event: HoverRatingChangeEvent = { hoverRating: this.hoverRating };
this.saveOnHover($event);


}

/**Form Control - ControlValueAccessor implementation**/
Expand Down Expand Up @@ -194,13 +195,12 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces

//if value changed trigger valueAccessor events and outputs
if (initValue !== this.rating) {
let $event: RatingChangeEvent = {rating: this.rating};
let $event: RatingChangeEvent = { rating: this.rating };
this.saveOnRatingChange($event);

this.saveOnModelChange(this.rating);
}

};
}

/**
* onStarClicked
Expand All @@ -213,7 +213,6 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces
* @param rating
*/
onStarClicked(rating: number): void {

//fire onClick event
if (!this.interactionPossible()) {
return;
Expand All @@ -225,7 +224,5 @@ export class StarRatingComponent extends StarRating implements ControlValueAcces
rating: this.rating
};
this.saveOnClick(onClickEventObject);

}

}
54 changes: 29 additions & 25 deletions libs/angular-star-rating/src/configs/default.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {starRatingColor} from '../interfaces/star-rating-config.interface';
export const getColor = function (rating: number, numOfStars: number, staticColor?: starRatingColor): starRatingColor {
import { starRatingColor } from '../interfaces/star-rating-config.interface';
export const getColor = function(
rating: number,
numOfStars: number,
staticColor?: starRatingColor
): starRatingColor {
rating = rating || 0;

// if a fix color is set use this one
if (staticColor) {
return staticColor
return staticColor;
}

// calculate size of smallest fraction
Expand All @@ -13,38 +17,38 @@ export const getColor = function (rating: number, numOfStars: number, staticColo
// apply color by fraction
let color: starRatingColor = 'default';
if (rating > 0) {
color = 'negative'
color = 'negative';
}
if (rating > fractionSize) {
color = 'ok'
color = 'ok';
}
if (rating > fractionSize * 2) {
color = 'positive'
color = 'positive';
}

return color
return color;
};
export const getHalfStarVisible = function (rating: number): boolean {
return Math.abs(rating % 1) > 0
export const getHalfStarVisible = function(rating: number): boolean {
return Math.abs(rating % 1) > 0;
};

export const defaultConfig = {
classEmpty: "default-star-empty-icon",
classHalf: "default-star-half-icon",
classFilled: "default-star-filled-icon",
classEmpty: 'default-star-empty-icon',
classHalf: 'default-star-half-icon',
classFilled: 'default-star-filled-icon',
numOfStars: 5,
size: "medium",
speed: "noticeable",
labelPosition: "left",
starType: "svg",
assetsPath: "assets/images/",
svgPath: this.assetsPath + "star-rating.icons.svg",
svgEmptySymbolId: "star-empty",
svgHalfSymbolId: "star-half",
svgFilledSymbolId: "star-filled",
svgPathEmpty: this.svgPath + "#" + this.svgEmptySymbolId,
svgPathHalf: this.svgPath + "#" + this.svgHalfSymbolId,
svgPathFilled: this.svgPath + "#" + this.svgFilledSymbolId,
size: 'medium',
speed: 'noticeable',
labelPosition: 'left',
starType: 'svg',
assetsPath: 'assets/images/',
svgPath: this.assetsPath + 'star-rating.icons.svg',
svgEmptySymbolId: 'star-empty',
svgHalfSymbolId: 'star-half',
svgFilledSymbolId: 'star-filled',
svgPathEmpty: this.svgPath + '#' + this.svgEmptySymbolId,
svgPathHalf: this.svgPath + '#' + this.svgHalfSymbolId,
svgPathFilled: this.svgPath + '#' + this.svgFilledSymbolId,
getColor: getColor,
getHalfStarVisible:getHalfStarVisible
getHalfStarVisible: getHalfStarVisible
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface HoverRatingChangeEvent {
hoverRating : number;
hoverRating: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export type starRatingColor = 'default' | 'negative' | 'ok' | 'positive';
export type starRatingSpeed = 'immediately' | 'noticeable' | 'slow';
export type starRatingLabelPosition = 'left' | 'right' | 'top' | 'bottom';
export type starRatingStarTypes = 'svg' | 'icon' | 'image';
export type starRatingStarSpace= 'no' | 'between' | 'around';
export type starRatingDirection= 'rtl' | 'ltr';
export type starRatingStarSpace = 'no' | 'between' | 'around';
export type starRatingDirection = 'rtl' | 'ltr';

export class StarRatingConfig {
// binding defaults
Expand All @@ -14,8 +14,12 @@ export class StarRatingConfig {
labelPosition?: starRatingLabelPosition;
starType?: starRatingStarTypes;
staticColor: starRatingColor;
getColor?: (rating: number, numOfStars: number, staticColor?: starRatingColor)=> starRatingColor;
getHalfStarVisible?:(rating: number) => boolean
getColor?: (
rating: number,
numOfStars: number,
staticColor?: starRatingColor
) => starRatingColor;
getHalfStarVisible?: (rating: number) => boolean;
// statics
classEmpty?: string;
classHalf?: string;
Expand Down
Loading

0 comments on commit 82e10c4

Please sign in to comment.