Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace is_js library #647

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions nav-app/package-lock.json

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

2 changes: 1 addition & 1 deletion nav-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"core-js": "^3.31.1",
"d3": "^7.8.5",
"d3-svg-legend": "^2.25.6",
"detect-browser": "^5.3.0",
"file-saver": "^2.0.5",
"is_js": "^0.9.0",
"load-json-file": "^7.0.1",
"mathjs": "^12.4.2",
"ngx-color-picker": "^16.0.0",
Expand Down
4 changes: 2 additions & 2 deletions nav-app/src/app/datatable/data-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { ViewModel } from '../classes';
import { DomSanitizer } from '@angular/platform-browser';
import { Subscription } from 'rxjs';
import * as Excel from 'exceljs/dist/exceljs.min.js';
import * as is from 'is_js';
import tinycolor from 'tinycolor2';
import { isIE } from '../utils/utils';

@Component({
selector: 'DataTable',
Expand Down Expand Up @@ -104,7 +104,7 @@ export class DataTableComponent implements AfterViewInit, OnDestroy {
* @param filename save as filename
*/
public saveBlob(blob, filename): void {
if (is.ie()) {
if (isIE()) {
// internet explorer
const nav = window.navigator as any;
nav.msSaveOrOpenBlob(blob, filename);
Expand Down
10 changes: 5 additions & 5 deletions nav-app/src/app/services/viewmodels.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventEmitter, Injectable, Output } from '@angular/core';
import { Gradient, TechniqueVM, ViewModel } from '../classes';
import { DataService } from './data.service';
import { evaluate } from 'mathjs';
import * as is from 'is_js';
import { isBoolean, isNumber } from '../utils/utils';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -98,10 +98,10 @@ export class ViewModelsService {

// if it didn't except after this, it evaluated to a single result
console.debug('score expression evaluated to single result to be applied to all techniques');
if (is.boolean(result)) {
if (isBoolean(result)) {
// boolean to binary
result = result ? '1' : '0';
} else if (is.not.number(result)) {
} else if (!isNumber(result)) {
// unexpected user input
throw Error('math result ( ' + result + ' ) is not a number');
}
Expand Down Expand Up @@ -139,10 +139,10 @@ export class ViewModelsService {
// did at least one technique have a score for this technique?
if (misses < scoreVariables.size) {
let mathResult = evaluate(opSettings.scoreExpression, scope);
if (is.boolean(mathResult)) {
if (isBoolean(mathResult)) {
// boolean to binary
mathResult = mathResult ? '1' : '0';
} else if (is.not.number(mathResult)) {
} else if (!isNumber(mathResult)) {
// unexpected user input
throw Error('math result ( ' + mathResult + ' ) is not a number');
}
Expand Down
4 changes: 2 additions & 2 deletions nav-app/src/app/svg-export/svg-export.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConfigService } from '../services/config.service';
import { DataService } from '../services/data.service';
import { RenderableMatrix, RenderableTactic, RenderableTechnique } from './renderable-objects';
import tinycolor from 'tinycolor2';
import * as is from 'is_js';
import { isIE } from '../utils/utils';
declare var d3: any; //d3js

@Component({
Expand Down Expand Up @@ -62,7 +62,7 @@ export class SvgExportComponent implements OnInit {

// browser compatibility
public get isIE(): boolean {
return is.ie();
return isIE();
}

// getters for visibility of SVG header sections
Expand Down
17 changes: 0 additions & 17 deletions nav-app/src/app/tabs/tabs.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { MatTabsModule } from "@angular/material/tabs";
import { ConfigService } from "../services/config.service";
import * as MockData from '../../tests/utils/mock-data';
import * as MockLayers from '../../tests/utils/mock-layers';
import * as is from 'is_js';
import { of } from "rxjs";
import { ChangelogComponent } from "../changelog/changelog.component";
import { HelpComponent } from "../help/help.component";
Expand Down Expand Up @@ -93,22 +92,6 @@ describe('TabsComponent', () => {
});
});

describe('ngAfterViewInit', () => {
it('should open Safari warning for Safari version <= 13', () => {
spyOn(is, 'safari').withArgs('<=13').and.returnValue(true);
let dialogSpy = spyOn(dialog, 'open');
component.ngAfterViewInit();
expect(dialogSpy).toHaveBeenCalled();
});

it('should not open Safari warning for Safari version > 13 or non-Safari browsers', () => {
spyOn(is, 'safari').withArgs('<=13').and.returnValue(false);
let dialogSpy = spyOn(dialog, 'open');
component.ngAfterViewInit();
expect(dialogSpy).not.toHaveBeenCalled();
});
});

describe('loadTabs', () => {
it('should load bundle when all fragment values are provided', async () => {
let bundleURL = 'testbundleurl';
Expand Down
4 changes: 2 additions & 2 deletions nav-app/src/app/tabs/tabs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { MatSnackBar } from '@angular/material/snack-bar';
import { HttpClient } from '@angular/common/http';
import { ChangelogComponent } from '../changelog/changelog.component';
import { Subscription, forkJoin } from 'rxjs';
import * as is from 'is_js';
import * as globals from '../utils/globals';
import { LayerInformationComponent } from '../layer-information/layer-information.component';
import { isSafari } from '../utils/utils';

@Component({
selector: 'tabs',
Expand Down Expand Up @@ -94,7 +94,7 @@ export class TabsComponent implements AfterViewInit {
}

ngAfterViewInit(): void {
if (is.safari('<=13')) {
if (isSafari('<=13')) {
// open safari version incompatibility warning
this.safariDialogRef = this.dialog.open(this.safariWarning, {
width: '350px',
Expand Down
34 changes: 34 additions & 0 deletions nav-app/src/app/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// utils.ts
import { detect } from "detect-browser";

let comparatorFn = {
'<': function(a, b) { return a < b; },
'<=': function(a, b) { return a <= b; },
'>': function(a, b) { return a > b; },
'>=': function(a, b) { return a >= b; }
};

export function isBoolean(value: any): boolean {
return typeof value === 'boolean';
}

export function isNumber(value: any): boolean {
return typeof value === 'number';
}

export function isIE(): boolean {
const browser = detect();
return browser.name == 'ie';
}

export function isSafari(compRange): boolean {
function compare(version, comp) {
let str = (comp + '');
let n = +(/\d+/.exec(str) || NaN);
let op = /^[<>]=?/.exec(str)[0];
return comparatorFn[op] ? comparatorFn[op](version, n) : (version == n || Number.isNaN(n));
}

const browser = detect();
return browser.name == 'safari' && compare(browser.version.split('.')[0], compRange);
}