-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Missed some files from last commit. Also new npm token since the inci…
…dent.
- Loading branch information
Showing
5 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ModelApiClient } from "@/api-client"; | ||
import * as $models from "./targets.models" | ||
import * as $metadata from "./targets.metadata" | ||
|
||
export class StudentApiClient extends ModelApiClient<$models.Student> { | ||
constructor() { super($metadata.Student) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import { ObjectType, BasicCollectionProperty, getEnumMeta, ObjectProperty, ModelType, ModelCollectionNavigationProperty, ClassType } from "@/metadata"; | ||
|
||
const metaBase = (name: string = "model") => { | ||
return { | ||
name: name, | ||
displayName: name.substr(0, 1).toUpperCase() + name.substr(1) | ||
}; | ||
}; | ||
|
||
const value = (name: string = "prop") => { | ||
return { | ||
name: name, | ||
displayName: name.substr(0, 1).toUpperCase() + name.substr(1), | ||
role: "value" | ||
}; | ||
}; | ||
|
||
const Types: { [key: string]: ClassType } = {}; | ||
export default Types; | ||
|
||
export const Course = Types.Course = <ModelType>{ | ||
...metaBase("course"), | ||
type: "model", | ||
get keyProp() { | ||
return this.props.courseId; | ||
}, | ||
get displayProp() { | ||
return this.props.name; | ||
}, | ||
controllerRoute: "Courses", | ||
dataSources: {}, | ||
methods: {}, | ||
props: { | ||
courseId: { | ||
...value("courseId"), | ||
type: "number" | ||
}, | ||
name: { | ||
...value("name"), | ||
type: "string" | ||
} | ||
} | ||
}; | ||
|
||
export const Advisor = Types.Advisor = <ModelType>{ | ||
...metaBase("advisor"), | ||
type: "model", | ||
get keyProp() { | ||
return this.props.advisorId; | ||
}, | ||
get displayProp() { | ||
return this.props.name; | ||
}, | ||
controllerRoute: "Advisors", | ||
dataSources: {}, | ||
methods: {}, | ||
props: { | ||
advisorId: { | ||
...value("advisorId"), | ||
type: "number" | ||
}, | ||
name: { | ||
...value("name"), | ||
type: "string" | ||
} | ||
} | ||
}; | ||
|
||
export const Student = Types.Student = <ModelType>{ | ||
...metaBase("student"), | ||
type: "model", | ||
get displayProp() { | ||
return this.props.name; | ||
}, | ||
get keyProp() { | ||
return this.props.studentId; | ||
}, | ||
controllerRoute: "Students", | ||
dataSources: {}, | ||
methods: {}, | ||
props: { | ||
studentId: { | ||
...value("studentId"), | ||
type: "number" | ||
}, | ||
name: { | ||
...value("name"), | ||
type: "string" | ||
}, | ||
isEnrolled: { | ||
...value("isEnrolled"), | ||
type: "boolean" | ||
}, | ||
birthDate: { | ||
...value("birthDate"), | ||
type: "date" | ||
}, | ||
courses: <ModelCollectionNavigationProperty>{ | ||
...value("courses"), | ||
role: "collectionNavigation", | ||
type: "collection", | ||
dontSerialize: true, | ||
itemType: { | ||
...value("$collectionValue"), | ||
type: "model", | ||
typeDef: Course, | ||
} | ||
}, | ||
grade: { | ||
...value("grade"), | ||
type: "enum", | ||
typeDef: { | ||
name: "grades", | ||
displayName: "Grades", | ||
type: "enum", | ||
...getEnumMeta([ | ||
{ value: 9, strValue: "Freshman", displayName: "Freshman" }, | ||
{ value: 10, strValue: "Sophomore", displayName: "Sophomore" }, | ||
{ value: 11, strValue: "Junior", displayName: "Junior" }, | ||
{ value: 12, strValue: "Senior", displayName: "Senior" } | ||
]) | ||
} | ||
}, | ||
advisor: { | ||
name: "advisor", | ||
displayName: "Advisor", | ||
type: "model", | ||
role: "referenceNavigation", | ||
dontSerialize: true, | ||
get foreignKey() { return Types.Student.props.advisorId }, | ||
get principalKey() { return Advisor.keyProp }, | ||
typeDef: Advisor | ||
}, | ||
advisorId: { | ||
name: "advisorId", | ||
displayName: "AdvisorId", | ||
type: "number", | ||
role: "foreignKey", | ||
get navigationProp() { return Types.Student.props.advisor }, | ||
get principalType() { return Types.Advisor }, | ||
get principalKey() { return Advisor.keyProp } | ||
} | ||
} | ||
}; | ||
|
||
export const DisplaysStudent = <ObjectType>{ | ||
...metaBase("displaysStudent"), | ||
type: "object", | ||
get displayProp() { | ||
return this.props.student; | ||
}, | ||
props: { | ||
name: { | ||
...value("name"), | ||
type: "string" | ||
}, | ||
student: { | ||
...value("student"), | ||
type: "model", | ||
dontSerialize: true, | ||
typeDef: Student | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as metadata from './targets.metadata' | ||
import { Model, DataSource, convertToModel, mapToModel } from '@/model' | ||
|
||
export enum Grade { | ||
Freshman = 9, | ||
Sophomore = 10, | ||
Junior = 11, | ||
Senior = 12, | ||
} | ||
|
||
export interface Student extends Model<typeof metadata.Student> { | ||
studentId: number | null | ||
name: string | null | ||
isEnrolled: boolean | null | ||
birthDate: Date | null | ||
courses: Course[] | null | ||
grade: Grade | null | ||
advisor: Advisor | null | ||
advisorId: number | null | ||
} | ||
|
||
export interface Advisor extends Model<typeof metadata.Advisor> { | ||
advisorId: number | null | ||
name: string | null | ||
} | ||
|
||
export interface Course extends Model<typeof metadata.Course> { | ||
courseId: number | null | ||
name: string | null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as metadata from "./targets.metadata" | ||
import * as models from "./targets.models" | ||
import * as apiClients from "./targets.apiclients" | ||
import { ViewModel, ListViewModel, defineProps } from '@/viewmodel' | ||
|
||
export interface StudentViewModel extends models.Student {} | ||
export class StudentViewModel extends ViewModel<models.Student, apiClients.StudentApiClient> { | ||
constructor(initialData?: models.Student) { | ||
super(metadata.Student, new apiClients.StudentApiClient(), initialData) | ||
} | ||
} | ||
defineProps(StudentViewModel, metadata.Student) |