Document System Tutorial Part 6 - Creating Records in Documents (Current Progress)

Back to Previous Page

Structure:

models

channel.go

Back to Top

package models

import (
    "github.com/uadmin/uadmin"
)

// Channel !
type Channel struct {
    uadmin.Model
    Name string `uadmin:"required"`
}

document_group.go

Back to Top

package models

import (
    "github.com/uadmin/uadmin"
)

// DocumentGroup !
type DocumentGroup struct {
    uadmin.Model
    Group      uadmin.UserGroup
    GroupID    uint
    Document   Document
    DocumentID uint
    Read       bool
    Add        bool
    Edit       bool
    Delete     bool
}

// DocumentGroup function that returns string value
func (d *DocumentGroup) String() string {

    // Gives access to the fields in another model
    uadmin.Preload(d)

    // Returns the GroupName from the Group model
    return d.Group.GroupName
}

document_user.go

Back to Top

package models

import (
    "github.com/uadmin/uadmin"
)

// DocumentUser !
type DocumentUser struct {
    uadmin.Model
    User       uadmin.User
    UserID     uint
    Document   Document
    DocumentID uint
    Read       bool
    Add        bool
    Edit       bool
    Delete     bool
}

// DocumentUser function that returns string value
func (d *DocumentUser) String() string {

    // Gives access to the fields in another model
    uadmin.Preload(d)

    // Returns the full name from the User model
    return d.User.String()
}

document_version.go

Back to Top

package models

import (
    "fmt"
    "time"

    "github.com/uadmin/uadmin"
)

// DocumentVersion !
type DocumentVersion struct {
    uadmin.Model
    Document   Document
    DocumentID uint
    File       string `uadmin:"file"`
    Number     int    `uadmin:"help:version number"`
    Date       time.Time
}

// Returns the version number
func (d DocumentVersion) String() string {
    return fmt.Sprint(d.Number)
}

document.go

Back to Top

package models

import (
    "time"

    "github.com/uadmin/uadmin"
)

// Document !
type Document struct {
    uadmin.Model
    Name        string
    File        string `uadmin:"file"`
    Description string `uadmin:"html"`
    RawText     string `uadmin:"list_exclude"`
    Folder      Folder `uadmin:"filter"`
    FolderID    uint
    CreatedDate time.Time
    Channel     Channel `uadmin:"list_exclude"`
    ChannelID   uint
    CreatedBy   string
}

folder_group.go

Back to Top

package models

import (
    "github.com/uadmin/uadmin"
)

// FolderGroup !
type FolderGroup struct {
    uadmin.Model
    Group    uadmin.UserGroup
    GroupID  uint
    Folder   Folder
    FolderID uint
    Read     bool
    Add      bool
    Edit     bool
    Delete   bool
}

// FolderGroup function that returns string value
func (f *FolderGroup) String() string {

    // Gives access to the fields in another model
    uadmin.Preload(f)

    // Returns the GroupName from the Group model
    return f.Group.GroupName
}

folder_user.go

Back to Top

package models

import (
    "github.com/uadmin/uadmin"
)

// FolderUser !
type FolderUser struct {
    uadmin.Model
    User     uadmin.User
    UserID   uint
    Folder   Folder
    FolderID uint
    Read     bool
    Add      bool
    Edit     bool
    Delete   bool
}

// FolderUser function that returns string value
func (f *FolderUser) String() string {

    // Gives access to the fields in another model
    uadmin.Preload(f)

    // Returns the full name from the User model
    return f.User.String()
}

folder.go

Back to Top

package models

import (
    "github.com/uadmin/uadmin"
)

// Folder !
type Folder struct {
    uadmin.Model
    Name     string
    Parent   *Folder
    ParentID uint
}

main.go

Back to Top

package main

import (
    // Specify the username that you used inside github.com folder
    "github.com/username/document_system/models"
    "github.com/uadmin/uadmin"
)

func main() {
    // Register models to uAdmin
    uadmin.Register(
        models.Folder{},
        models.FolderGroup{},
        models.FolderUser{},
        models.Channel{},
        models.Document{},
        models.DocumentGroup{},
        models.DocumentUser{},
        models.DocumentVersion{},
    )

    // Assign Site Name value as "Document System"
    // NOTE: This code works only if database does not exist yet.
    uadmin.SiteName = "Document System"

    // Activates a uAdmin server
    uadmin.StartServer()
}

uadmin.db

Channels

Back to Top

../../../_images/channelmodelupdate.png

Documents

Back to Top

../../../_images/documentmodelupdate.png

Document Groups

Back to Top

../../../_images/documentgroupmodelupdate.png

Document Users

Back to Top

../../../_images/documentusermodelupdate.png

Document Versions

Back to Top

../../../_images/documentversionmodelupdate.png

Folder Groups

Back to Top

../../../_images/foldergroupmodelupdate.png

Folder Users

Back to Top

../../../_images/folderusermodelupdate.png

Folders

Back to Top

../../../_images/foldermodelupdate.png