Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Profile

the profile class handles profiles adding, renaming and deleting

note

profile selection is handled in the Store class because it also needs to manipulate other store modules

author

Hanzhi Zhou

Hierarchy

  • Profile

Index

Constructors

constructor

Properties

Private accessToken

accessToken: string

current

current: string

the name of the current profile. This is a reactive property. Whenever changed, the currentProfile in the localStorage will be updated

profiles

profiles: LocalProfileEntry[]

an array of local profile names and their associated information

tokenType

tokenType: string

the access token type. If this field is non-empty, that means we have a valid access token and can communicate with the backend.

Methods

addProfile

  • addProfile(newProfile: Partial<SemesterStorage>, fallbackName?: string, overwriteMsg?: string): Promise<undefined | { level: "error"; msg: string }>
  • parse a profile from string, add it to the list of profiles, store it in localStorage, and set Profile.current to be the newly added profile. If the newly added profile overwrites an existing profile that is marked as remote, also upload it to the remote

    note

    it is the caller's responsibility to call loadProfile() to load the newly added profile

    Parameters

    • newProfile: Partial<SemesterStorage>

      the profile to add

    • Default value fallbackName: string = "Untitled"

      the fallback name if newProfile does not contain the name of the profile

    • Default value overwriteMsg: string = ""

      the message shown to the user if there already exists a profile of the same name

    Returns Promise<undefined | { level: "error"; msg: string }>

createProfile

deleteProfile

  • deleteProfile(name: string, idx: number, requestRemote?: boolean): Promise<NotiMsg<string>>
  • delete a profile. If remote and requestRemote=true, also delete it from the remote.

    Parameters

    • name: string
    • idx: number
    • Default value requestRemote: boolean = true

    Returns Promise<NotiMsg<string>>

    A noti message containing the name of the previous profile if the deleted profile is selected, undefined otherwise

deleteRemote

getBackendToken

  • getBackendToken(code: string | null): Promise<boolean>

Private getRedirectURL

  • getRedirectURL(): string
  • get the redirect url for the authorization code flow. For the desktop app (electron), a configured uri will be used.

    Returns string

getRemoteProfile

initProfiles

isLatest

  • isLatest(idx: number): boolean

loadToken

  • loadToken(): void

loginBackend

  • redirect to the url for requesting an authorization code. It should redirect back with the code attached to the url.

    Returns Promise<void>

logout

  • logout(): void

renameProfile

  • renameProfile(idx: number, oldName: string, newName: string, raw: string): Promise<undefined | { level: "error"; msg: string }>
  • rename a profile. If remote=true, also rename the remote profile. note that name duplication is not checked! This check should be done by the caller.

    see

    ExportView.renameProfile

    Parameters

    • idx: number
    • oldName: string
    • newName: string
    • raw: string

      the content fetched from localStorage.getItem(oldName)

    Returns Promise<undefined | { level: "error"; msg: string }>

Private requestBackend

sha256

  • sha256(message: string): Promise<string>

syncProfiles

uploadProfile

  • upload the list of profiles given to the remote, and also update their version histories

    note

    the list of profiles given must be present in Profile.profiles. If not, Profile.addProfile must be called first.

    Parameters

    Returns Promise<undefined | { level: "error"; msg: string }>

    an error message when failed, undefined when success

Generated using TypeDoc