1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //go:generate reform --gofmt=false
- package asuModels
- import (
- "fmt"
- "html/template"
- )
- //reform:face
- type Person struct {
- EmpGUID int `reform:"EmpGUID" view:"readonly"`
- Lastname string `reform:"SurName" view:"readonly"`
- Firstname string `reform:"FirstName" view:"readonly"`
- Patronymic *string `reform:"MiddleName" view:"readonly"`
- Sex *int `reform:"Sex" view:"readonly"`
- Id int `reform:"_Id" view:"readonly"`
- BirthDay *string `reform:"BirthDay" view:"readonly"`
- Citizenship *int `reform:"Citizenship" view:"readonly"`
- CitizenType *string `reform:"CitizenType" view:"readonly"`
- Phone *string `reform:"Phone" view:"readonly"`
- Phone2 *string `reform:"Phone2" view:"readonly"`
- Phone3 *string `reform:"Phone3" view:"readonly"`
- formulars Formulars `reform:"-"`
- formularsReady bool `reform:"-"`
- }
- // TODO: Remove this "VIEW" from this model
- func (u Person) View_readTag(fieldName string, parent interface{}, args []interface{}) template.HTML {
- if u.EmpGUID == 0 {
- return template.HTML(fmt.Sprintf(`Не назначено`))
- }
- description := u.Lastname + " " + u.Firstname
- if u.Patronymic != nil {
- description += " " + *u.Patronymic
- }
- if u.BirthDay != nil {
- if len(*u.BirthDay) > len("1988-03-06") {
- description += " (" + (*u.BirthDay)[:len("1988-03-06")] + ")"
- }
- }
- return template.HTML(fmt.Sprintf(`<a href="/asu/people/%v?fullscreen=true">%v</a>`, u.EmpGUID, description))
- }
- type People []Person
- func (people People) Deduplicate() (deduplicated People) {
- personMap := map[int]*Person{}
- for idx, person := range people {
- personMap[person.EmpGUID] = &people[idx]
- }
- for _, person := range personMap {
- deduplicated = append(deduplicated, *person)
- }
- return
- }
- func (people People) GetEmpGUIDs() (empGUIDs []int) {
- for _, person := range people {
- empGUIDs = append(empGUIDs, person.EmpGUID)
- }
- return
- }
- func (person *Person) PrepareFormulars() *Person {
- var err error
- person.formulars, err = FormularSQL.Select(Formular{EmpGUID: person.EmpGUID})
- if err != nil {
- panic(err)
- }
- person.formularsReady = true
- return person
- }
- func (person Person) GetFormulars() Formulars {
- if !person.formularsReady {
- panic("person is not ready for method GetFormulars: it's required to call PrepareFormulars method, first")
- }
- return person.formulars
- }
|