Drew style (#403)

* mail icon

* working unique

Co-authored-by: Drew Ansbacher <drew.ansbacher@spiredigital.com>
This commit is contained in:
Drew Ansbacher
2021-08-10 18:41:35 -06:00
committed by Aiden McClelland
parent 3fcb96229e
commit 58678522ff
3 changed files with 84 additions and 16 deletions

View File

@@ -95,11 +95,12 @@ export class FormObjectComponent {
expanded: true, expanded: true,
displayAs: displayAs ? handlebars.compile(displayAs)(newItem.value) : '', displayAs: displayAs ? handlebars.compile(displayAs)(newItem.value) : '',
}) })
pauseFor(200).then(() => {
const index = this.objectListInfo[key].length - 1
this.objectListInfo[key][index].height = this.getDocSize(key)
})
} }
pauseFor(200).then(() => {
const index = this.objectListInfo[key].length - 1
this.objectListInfo[key][index].height = this.getDocSize(key)
})
} }
toggleExpand (key: string, i: number) { toggleExpand (key: string, i: number) {

View File

@@ -24,12 +24,12 @@
style=" style="
text-align: center; text-align: center;
position: absolute; position: absolute;
top: 40%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%, -50%);" transform: translate(-50%, -50%);"
> >
<ion-icon style="font-size: 84px; color: #282c33" name="mail-outline"></ion-icon> <ion-icon style="font-size: 84px; color: #2c3038" name="mail-outline"></ion-icon>
<h4 style="color: #282c33; margin-top: 0px">Inbox Empty</h4> <h4 style="color: #2c3038; margin-top: 0px">Inbox Empty</h4>
</div> </div>
</ion-item-group> </ion-item-group>

View File

@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { AbstractControl, FormArray, FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms' import { AbstractControl, FormArray, FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'
import { ConfigSpec, isValueSpecListOf, ListValueSpecNumber, ListValueSpecString, ListValueSpecUnion, ValueSpec, ValueSpecEnum, ValueSpecList, ValueSpecNumber, ValueSpecObject, ValueSpecString, ValueSpecUnion } from '../pkg-config/config-types' import { By } from '@angular/platform-browser'
import { ConfigSpec, isValueSpecListOf, ListValueSpecNumber, ListValueSpecObject, ListValueSpecOf, ListValueSpecString, ListValueSpecUnion, UniqueBy, ValueSpec, ValueSpecEnum, ValueSpecList, ValueSpecNumber, ValueSpecObject, ValueSpecString, ValueSpecUnion } from '../pkg-config/config-types'
import { getDefaultString, Range } from '../pkg-config/config-utilities' import { getDefaultString, Range } from '../pkg-config/config-utilities'
@Injectable({ @Injectable({
@@ -213,32 +214,98 @@ export function listInRange (stringRange: string): ValidatorFn {
} }
} }
export function listUnique (spec: ValueSpec): ValidatorFn { export function listUnique (spec: ValueSpecList): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => { return (control: AbstractControl): ValidationErrors | null => {
for (let idx = 0; idx < control.value.length; idx++) { for (let idx = 0; idx < control.value.length; idx++) {
for (let idx2 = idx + 1; idx2 < control.value.length; idx2++) { for (let idx2 = idx + 1; idx2 < control.value.length; idx2++) {
if (equals(spec, control.value[idx], control.value[idx2])) { if (listItemEquals(spec, control.value[idx], control.value[idx2])) {
return { listNotUnique: { value: control.value } } return { listNotUnique: { value: control.value } }
} else {
return null
} }
} }
} }
return null
} }
} }
export function equals (spec: ValueSpec, val1: any, val2: any): boolean { function listItemEquals (spec: ValueSpecList, val1: any, val2: any): boolean {
switch (spec.subtype) {
case 'string':
case 'number':
case 'enum':
return val1 == val2
case 'object':
case 'union':
return listObjEquals(spec.spec['unique-by'], (spec.spec as ListValueSpecObject), val1, val2)
default:
return false
}
}
function itemEquals (spec: ValueSpec, val1: any, val2: any): boolean {
switch (spec.type) { switch (spec.type) {
case 'string': case 'string':
case 'number': case 'number':
case 'boolean': case 'boolean':
case 'enum': case 'enum':
return val1 === val2 return val1 == val2
case 'object': case 'object':
case 'union': case 'union':
// @TODO how to check this return objEquals(spec['unique-by'], (spec as ValueSpec), val1, val2)
return false case 'list':
if (val1.length !== val2.length) {
return false
}
for (let idx = 0; idx < val1.length; idx++) {
if (listItemEquals(spec, val1[idx], val2[idx])) {
return false
}
}
return true
default: default:
return false return false
} }
} }
function listObjEquals (uniqueBy: UniqueBy, spec: ListValueSpecObject, val1: any, val2: any): boolean {
if (uniqueBy === null) {
return false
} else if (typeof uniqueBy === 'string') {
return itemEquals(spec.spec[uniqueBy], val1[uniqueBy], val2[uniqueBy])
} else if ('any' in uniqueBy) {
for (let subSpec of uniqueBy.any) {
if (listObjEquals(subSpec, spec, val1, val2)) {
return true
}
}
return false
} else if ('all' in uniqueBy) {
for (let subSpec of uniqueBy.all) {
if (!listObjEquals(subSpec, spec, val1, val2)) {
return false
}
}
return true
}
}
function objEquals (uniqueBy: UniqueBy, spec: ValueSpec, val1: any, val2: any): boolean {
if (uniqueBy === null) {
return false
} else if (typeof uniqueBy === 'string') {
return itemEquals(spec, val1, val2)
} else if ('any' in uniqueBy) {
for (let subSpec of uniqueBy.any) {
if (objEquals(subSpec, spec, val1, val2)) {
return true
}
}
return false
} else if ('all' in uniqueBy) {
for (let subSpec of uniqueBy.all) {
if (!objEquals(subSpec, spec, val1, val2)) {
return false
}
}
return true
}
}