fix(favorites): make favorites work with configurable views
continuous-integration/drone/push Build is failing Details

This commit is contained in:
kolaente 2024-04-14 17:12:16 +02:00
parent 2d084c091e
commit d8ca1a2de1
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 51 additions and 7 deletions

View File

@ -8,7 +8,6 @@ const SETTINGS_KEY_PROJECT_VIEW = 'projectView'
* Save the current project view to local storage
*/
export function saveProjectView(projectId: IProject['id'], viewId: number) {
console.log({projectId, viewId})
if (!projectId || !viewId) {
return
}

View File

@ -112,15 +112,43 @@ type ProjectBackgroundType struct {
// ProjectBackgroundUpload represents the project upload background type
const ProjectBackgroundUpload string = "upload"
const FavoritesPseudoProjectID = -1
// FavoritesPseudoProject holds all tasks marked as favorites
var FavoritesPseudoProject = Project{
ID: -1,
ID: FavoritesPseudoProjectID,
Title: "Favorites",
Description: "This project has all tasks marked as favorites.",
IsFavorite: true,
Position: -1,
Created: time.Now(),
Updated: time.Now(),
Views: []*ProjectView{
{
ID: -1,
ProjectID: FavoritesPseudoProjectID,
Title: "List",
ViewKind: ProjectViewKindList,
Position: 100,
Filter: "done = false",
},
{
ID: -2,
ProjectID: FavoritesPseudoProjectID,
Title: "Gantt",
ViewKind: ProjectViewKindGantt,
Position: 200,
},
{
ID: -3,
ProjectID: FavoritesPseudoProjectID,
Title: "Table",
ViewKind: ProjectViewKindTable,
Position: 300,
},
},
Created: time.Now(),
Updated: time.Now(),
}
// ReadAll gets all projects a user has access to
@ -212,6 +240,7 @@ func (p *Project) ReadAll(s *xorm.Session, a web.Auth, search string, page int,
func (p *Project) ReadOne(s *xorm.Session, a web.Auth) (err error) {
if p.ID == FavoritesPseudoProject.ID {
p.Views = FavoritesPseudoProject.Views
// Already "built" the project in CanRead
return nil
}

View File

@ -347,10 +347,22 @@ func (p *ProjectView) Update(s *xorm.Session, _ web.Auth) (err error) {
return
}
func GetProjectViewByIDAndProject(s *xorm.Session, id, projectID int64) (view *ProjectView, err error) {
func GetProjectViewByIDAndProject(s *xorm.Session, viewID, projectID int64) (view *ProjectView, err error) {
if projectID == FavoritesPseudoProjectID && viewID < 0 {
for _, v := range FavoritesPseudoProject.Views {
if v.ID == viewID {
return v, nil
}
}
return nil, &ErrProjectViewDoesNotExist{
ProjectViewID: viewID,
}
}
view = &ProjectView{}
exists, err := s.
Where("id = ? AND project_id = ?", id, projectID).
Where("id = ? AND project_id = ?", viewID, projectID).
NoAutoCondition().
Get(view)
if err != nil {
@ -359,7 +371,7 @@ func GetProjectViewByIDAndProject(s *xorm.Session, id, projectID int64) (view *P
if !exists {
return nil, &ErrProjectViewDoesNotExist{
ProjectViewID: id,
ProjectViewID: viewID,
}
}

View File

@ -100,6 +100,10 @@ func getTaskFilterOptsFromCollection(tf *TaskCollection, projectView *ProjectVie
param.orderBy = getSortOrderFromString(tf.OrderBy[i])
}
if s == taskPropertyPosition && projectView != nil && projectView.ID < 0 {
continue
}
if s == taskPropertyPosition && projectView != nil {
param.projectViewID = projectView.ID
}