Skip to content

Commit

Permalink
implement missing games tab
Browse files Browse the repository at this point in the history
Add indication to configuration order
  • Loading branch information
giwty authored and giwty committed Feb 22, 2021
1 parent 9b8545d commit 7330561
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 7 deletions.
2 changes: 1 addition & 1 deletion console.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *Console) Start() {
scanFolders := settingsObj.ScanFolders
scanFolders = append(scanFolders, folderToScan)

localDB, err := localDbManager.CreateLocalSwitchFilesDB(scanFolders, c, recursiveMode, false)
localDB, err := localDbManager.CreateLocalSwitchFilesDB(scanFolders, c, recursiveMode, true)
if err != nil {
fmt.Printf("\nfailed to process local folder\n %v", err)
return
Expand Down
39 changes: 39 additions & 0 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ type LocalLibraryData struct {
NumFiles int `json:"num_files"`
}

type SwitchTitle struct {
Name string `json:"name"`
TitleId string `json:"titleId"`
Icon string `json:"icon"`
Region string `json:"region"`
ReleaseDate int `json:"release_date"`
}

type LibraryTemplateData struct {
Id int `json:"id"`
Name string `json:"name"`
Expand Down Expand Up @@ -197,6 +205,10 @@ func (g *GUI) handleMessage(m *astilectron.EventMessage) interface{} {
g.state.window.SendMessage(Message{Name: "error", Payload: err.Error()}, func(m *astilectron.EventMessage) {})
return ""
}
case "missingGames":
missingGames := g.getMissingGames()
msg, _ := json.Marshal(missingGames)
g.state.window.SendMessage(Message{Name: "missingGames", Payload: string(msg)}, func(m *astilectron.EventMessage) {})
case "updateLocalLibrary":
ignoreCache, _ := strconv.ParseBool(msg.Payload)
localDB, err := g.buildLocalDB(g.localDbManager, ignoreCache)
Expand Down Expand Up @@ -400,6 +412,12 @@ func (g *GUI) buildLocalDB(localDbManager *db.LocalSwitchDBManager, ignoreCache

func (g *GUI) organizeLibrary() {
folderToScan := settings.ReadSettings(g.baseFolder).Folder
options := settings.ReadSettings(g.baseFolder).OrganizeOptions
if !process.IsOptionsValid(options) {
zap.S().Error("the organize options in settings.json are not valid, please check that the template contains file/folder name")
g.state.window.SendMessage(Message{Name: "error", Payload: "the organize options in settings.json are not valid, please check that the template contains file/folder name"}, func(m *astilectron.EventMessage) {})
return
}
process.OrganizeByFolders(folderToScan, g.state.localDB, g.state.switchDB, g)
if settings.ReadSettings(g.baseFolder).OrganizeOptions.DeleteOldUpdateFiles {
process.DeleteOldUpdates(g.baseFolder, g.state.localDB, g)
Expand All @@ -417,3 +435,24 @@ func (g *GUI) UpdateProgress(curr int, total int, message string) {

g.state.window.SendMessage(Message{Name: "updateProgress", Payload: string(msg)}, func(m *astilectron.EventMessage) {})
}

func (g *GUI) getMissingGames() []SwitchTitle {
var result []SwitchTitle
for k, v := range g.state.switchDB.TitlesMap {
if _, ok := g.state.localDB.TitlesMap[k]; ok {
continue
}
if v.Attributes.Name == "" || v.Attributes.Id == "" {
continue
}
result = append(result, SwitchTitle{
TitleId: v.Attributes.Id,
Name: v.Attributes.Name,
Icon: v.Attributes.BannerUrl,
Region: v.Attributes.Region,
ReleaseDate: v.Attributes.ReleaseDate,
})
}
return result

}
4 changes: 2 additions & 2 deletions process/organizefolderStructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func OrganizeByFolders(baseFolder string,
//validate template rules

options := settings.ReadSettings(baseFolder).OrganizeOptions
if !isOptionsValid(options) {
if !IsOptionsValid(options) {
zap.S().Error("the organize options in settings.json are not valid, please check that the template contains file/folder name")
return
}
Expand Down Expand Up @@ -212,7 +212,7 @@ func OrganizeByFolders(baseFolder string,
}
}

func isOptionsValid(options settings.OrganizeOptions) bool {
func IsOptionsValid(options settings.OrganizeOptions) bool {
if options.RenameFiles {
if options.FileNameTemplate == "" {
zap.S().Error("file name template cannot be empty")
Expand Down
23 changes: 20 additions & 3 deletions resources/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,26 @@ <h5 class="progress-type">Loading...</h5>
</script>

<script id="missingTemplate" type="text/x-jsrender">
<div class="alert alert-success" role="alert">
coming soon!
</div>
{{if folder}}
{{if missingGames && missingGames.length}}
<div class="alert center alert-warning" role="alert">
There are {{:missingGames.length}} games missing in your local library:
<button type="button" class="btn btn-link export-btn">export to scv</button>

This comment has been minimized.

Copy link
@uaktags

uaktags Apr 26, 2021

#72
spelling issue here.

</div>
<section id="missingGames-table" class="content"></section>
{{else}}
<div class="alert center alert-success" role="alert">
You have all the games, you are not missing any Games!
</div>
{{/if}}
{{else}}
<div class="alert center alert-warning" role="alert">
Local games folder is not set, please set the folder to get started
</div>
<div class="center">
<button type="button" class="btn btn-outline-primary folder-set">Set Folder</button>
</div>
{{/if}}
</script>

<script id="libraryTemplate" type="text/x-jsrender">
Expand Down
35 changes: 34 additions & 1 deletion resources/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ $(function () {
state.library = JSON.parse(message.payload);
loadTab("#library")
}
else if (message.name === "missingGames") {
state.missingGames = JSON.parse(message.payload);
loadTab("#missing")
}
else if (message.name === "error") {
dialog.showMessageBox(null, {
type: 'error',
Expand Down Expand Up @@ -293,8 +297,37 @@ $(function () {
});
}
}else if (target === "#missing") {
let html = $(target + "Template").render({folder: state.settings.folder,settings:state.settings})
if (state.settings.folder && !state.library){
return
}
if (state.library && !state.missingGames){
sendMessage("missingGames", "", (r => {
state.missingGames = JSON.parse(r)
loadTab("#missing")
}));
return
}
let html = $(target + "Template").render({folder: state.settings.folder,missingGames:state.missingGames});
$(target).html(html);
if (state.missingGames && state.missingGames.length) {
currTable = new Tabulator("#missingGames-table", {
layout:"fitDataStretch",
initialSort:[
{column:"name", dir:"asc"}, //sort by this first
],
pagination: "local",
paginationSize: state.settings.gui_page_size,
data: state.missingGames,
columns: [
{formatter:"rownum"},
{field: "icon",download:false,formatter:"image", headerSort:false,formatterParams:{height:"60px", width:"60px"}},
{field: "name",title: "Title", headerFilter:"input",formatter:"textarea",width:350},
{title: "Title id", headerSort:false, field: "titleId"},
{title: "Region", headerSort:true,headerFilter:"input",formatter:"textarea", field: "region"},
{title: "Release date", headerSort:true, field: "release_date"},
],
});
}
}
}

Expand Down

0 comments on commit 7330561

Please sign in to comment.