-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2ad9f9
commit 55b3712
Showing
4 changed files
with
307 additions
and
0 deletions.
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,82 @@ | ||
package ysk | ||
|
||
type CartType string | ||
|
||
const ( | ||
CardTypeTask CartType = "task" | ||
CardTypeLongNote CartType = "long-notice" | ||
CardTypeShortNote CartType = "short-notice" | ||
) | ||
|
||
type RenderType string | ||
|
||
const ( | ||
RenderTypeCardTask RenderType = "task" | ||
RenderTypeCardListNotice RenderType = "list-notice" | ||
RenderTypeCardIconTextNotice RenderType = "icon-text-notice" | ||
RenderTypeCardMarkdownNotice RenderType = "markdown-notice" | ||
) | ||
|
||
type ActionPosition string | ||
|
||
const ( | ||
ActionPositionLeft ActionPosition = "left" | ||
ActionPositionRight ActionPosition = "right" | ||
) | ||
|
||
type YSKCard struct { | ||
ID string | ||
CardType CartType | ||
RenderType RenderType | ||
Content YSKCardContent | ||
} | ||
|
||
func (yskCard YSKCard) WithProgress(label string, progress int) YSKCard { | ||
if yskCard.Content.BodyProgress != nil { | ||
yskCard.Content.BodyProgress = &YSKCardProgress{ | ||
Label: label, | ||
Value: progress, | ||
} | ||
return yskCard | ||
} | ||
return yskCard | ||
} | ||
|
||
type YSKCardContent struct { | ||
TitleIcon string | ||
TitleText string | ||
BodyProgress *YSKCardProgress | ||
BodyIconWithText *YSKCardIconWithText | ||
BodyList []YSKCardListItem | ||
FooterActions []YSKCardFooterAction | ||
} | ||
|
||
type YSKCardProgress struct { | ||
Label string | ||
Value int | ||
} | ||
|
||
type YSKCardIconWithText struct { | ||
Icon string | ||
Description string | ||
} | ||
|
||
type YSKCardListItem struct { | ||
Icon string | ||
Description string | ||
RightText string | ||
} | ||
|
||
type YSKCardFooterAction struct { | ||
Side ActionPosition | ||
Style string | ||
Text string | ||
MessageBus YSKCardMessageBusAction | ||
} | ||
|
||
type YSKCardMessageBusAction struct { | ||
Key string | ||
Payload string | ||
} | ||
|
||
type YSKCardIcon = string |
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,27 @@ | ||
package ysk | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
) | ||
|
||
const ( | ||
SERVICENAME = "ysk" | ||
) | ||
|
||
func DefineCard(ctx context.Context, cardID string) YSKCard { | ||
return YSKCard{} | ||
} | ||
|
||
func NewYSKCard(ctx context.Context, YSKCard YSKCard, publish func(context.Context, string, string, map[string]string)) error { | ||
// do something | ||
yskCardBodyJSON, _ := json.Marshal(YSKCard) | ||
publish(ctx, SERVICENAME, "ysk:card:create", map[string]string{"body": string(yskCardBodyJSON)}) | ||
return nil | ||
} | ||
|
||
func DeleteCard(ctx context.Context, cardID string, publish func(context.Context, string, string, map[string]string)) error { | ||
// do something | ||
publish(ctx, SERVICENAME, "ysk:card:delete", map[string]string{"body": string(``)}) | ||
return nil | ||
} |
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,33 @@ | ||
package ysk_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/IceWhaleTech/ZimaOS/pkg/ysk" | ||
) | ||
|
||
func TestUpdateProgress(t *testing.T) { | ||
ApplicationInstallProgress := ysk.YSKCard{ | ||
ID: "task:application:install", | ||
CardType: ysk.CardTypeTask, | ||
RenderType: ysk.RenderTypeCardTask, | ||
Content: ysk.YSKCardContent{ | ||
TitleIcon: "jellyfin logo", | ||
TitleText: "APP Installing", | ||
BodyProgress: &ysk.YSKCardProgress{}, | ||
BodyIconWithText: nil, | ||
BodyList: nil, | ||
FooterActions: nil, | ||
}, | ||
} | ||
|
||
ysk.NewYSKCard(context.Background(), ApplicationInstallProgress.WithProgress( | ||
"Installing LinuxServer/Jellyfin", | ||
50, | ||
), nil) | ||
|
||
ysk.DeleteCard(context.Background(), ApplicationInstallProgress.ID, nil) | ||
} | ||
|
||
func TestNoticeInUser |