Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
866
Issues
866
List
Boards
Labels
Service Desk
Milestones
Merge Requests
53
Merge Requests
53
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Frontend
Commits
3f7c0e7e
Commit
3f7c0e7e
authored
24 minutes ago
by
Ben Hayward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed up tests and formatted
parent
6c70490d
fix/boost-console-feed-1596
1 merge request
!501
[Sprint/LuckyLizard](fix) Boost console feed #1596
Pipeline
#77188176
canceled with stages
in 19 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
94 deletions
+99
-94
feeds.service.ts
src/app/common/services/feeds.service.ts
+8
-6
booster.component.html
src/app/modules/boost/console/booster/booster.component.html
+8
-7
booster.component.spec.ts
...p/modules/boost/console/booster/booster.component.spec.ts
+21
-26
booster.component.ts
src/app/modules/boost/console/booster/booster.component.ts
+61
-54
feed-service-mock.spec.ts
src/tests/feed-service-mock.spec.ts
+1
-1
No files found.
src/app/common/services/feeds.service.ts
View file @
3f7c0e7e
...
...
@@ -140,9 +140,9 @@ export class FeedsService {
* Fetches the data.
*/
fetch
():
FeedsService
{
if
(
!
this
.
offset
.
getValue
())
if
(
!
this
.
offset
.
getValue
())
{
this
.
inProgress
.
next
(
true
);
}
this
.
client
.
get
(
this
.
endpoint
,
{
...
this
.
params
,
...{
...
...
@@ -151,9 +151,12 @@ export class FeedsService {
from_timestamp
:
this
.
pagingToken
,
}})
.
then
((
response
:
any
)
=>
{
if
(
!
this
.
offset
.
getValue
())
if
(
!
this
.
offset
.
getValue
())
{
this
.
inProgress
.
next
(
false
);
}
if
(
!
response
.
entities
&&
response
.
activity
)
{
response
.
entities
=
response
.
activity
;
}
if
(
response
.
entities
.
length
)
{
this
.
rawFeed
.
next
(
this
.
rawFeed
.
getValue
().
concat
(
response
.
entities
));
this
.
pagingToken
=
response
[
'
load-next
'
];
...
...
@@ -161,8 +164,7 @@ export class FeedsService {
this
.
canFetchMore
=
false
;
}
})
.
catch
(
err
=>
{
});
.
catch
(
e
=>
console
.
log
(
e
));
return
this
;
}
...
...
This diff is collapsed.
Click to expand it.
src/app/modules/boost/console/booster/booster.component.html
View file @
3f7c0e7e
...
...
@@ -4,6 +4,7 @@
</div>
<div
class=
"m-boost-console-booster--content"
>
<!-- Posts -->
<ng-container
*ngIf=
"type == 'newsfeed' || type == 'offers'"
>
<ng-container>
...
...
@@ -12,13 +13,13 @@
</div>
</ng-container>
<h3
[hidden]=
"
!inProgress && (feed$ | async)?.length !> 0
"
i18n=
"@@BOOST__CONSOLE__BOOSTER__POST_SOMETHING"
>
You have no content yet. Why don't you post
<h3
[hidden]=
"
noContent
"
i18n=
"@@BOOST__CONSOLE__BOOSTER__POST_SOMETHING"
>
You have no content yet. Why don't you post
something?
</h3>
<div
*ngIf=
"inProgress"
class=
"mdl-spinner mdl-js-spinner is-active"
[
mdl
]
></div>
<div
#poster
[hidden]=
"
!inProgress && (feed$ | async)?.length !> 0
"
>
<div
#poster
[hidden]=
"
noContent
"
>
</div>
</ng-container>
...
...
@@ -28,23 +29,23 @@
<h3
i18n=
"@@BOOST__CONSOLE__BOOSTER__YOUR_CHANNEL_TITLE"
>
Your channel
</h3>
<minds-card
[object]=
"session.getLoggedInUser()"
hostClass=
"mdl-shadow--2dp"
></minds-card>
<ng-container
*ngIf=
"(feed$ | async)?.length
>
0"
>
<ng-container
*ngIf=
"(feed$ | async)?.length
!=
0"
>
<h3
i18n=
"@@BOOST__CONSOLE__BOOSTER__YOUR_RECENT_MEDIA_TITLE"
>
Your recent media
</h3>
<div
class=
"mdl-grid m-boost-console-booster--content-grid"
>
<div
class=
"mdl-cell mdl-cell--6-col"
*ngFor=
"let entity of (feed$ | async)
; let i = index
"
>
<div
class=
"mdl-cell mdl-cell--6-col"
*ngFor=
"let entity of (feed$ | async)"
>
<minds-card
[object]=
"entity | async"
hostClass=
"mdl-shadow--2dp"
></minds-card>
<minds-button
type=
"boost"
[object]=
"entity | async"
></minds-button>
</div>
</div>
</ng-container>
<h3
[hidden]=
"
!inProgress && (feed$ | async)?.length !> 0
"
i18n=
"@@BOOST__CONSOLE__BOOSTER__POST_SOMETHING"
>
You have no content yet. Why don't you post
<h3
[hidden]=
"
noContent
"
i18n=
"@@BOOST__CONSOLE__BOOSTER__POST_SOMETHING"
>
You have no content yet. Why don't you post
something?
</h3>
<div
*ngIf=
"inProgress"
class=
"mdl-spinner mdl-js-spinner is-active"
[
mdl
]
></div>
<div
#poster
[hidden]=
"
!inProgress && (feed$ | async)?.length !> 0
"
>
<div
#poster
[hidden]=
"
noContent
"
>
</div>
</ng-container>
...
...
@@ -52,7 +53,7 @@
<infinite-scroll
distance=
"25%"
(load)=
"loadNext()"
[moreData]=
"
haveMoreData()
"
[moreData]=
"
feedsService.hasMore | async
"
[inProgress]=
"inProgress"
></infinite-scroll>
</div>
This diff is collapsed.
Click to expand it.
src/app/modules/boost/console/booster/booster.component.spec.ts
View file @
3f7c0e7e
...
...
@@ -4,8 +4,7 @@ import { ReactiveFormsModule } from '@angular/forms';
import
{
RouterTestingModule
}
from
'
@angular/router/testing
'
;
import
{
By
}
from
'
@angular/platform-browser
'
;
import
{
BoostConsoleBooster
}
from
'
./booster.component
'
;
import
{
clientMock
,
}
from
'
../../../../../tests/client-mock.spec
'
;
import
{
feedsServiceMock
}
from
'
../../../../../tests/feed-service-mock.spec
'
;
import
{
clientMock
}
from
'
../../../../../tests/client-mock.spec
'
;
import
{
sessionMock
}
from
'
../../../../../tests/session-mock.spec
'
;
import
{
MockComponent
,
MockDirective
}
from
'
../../../../utils/mock
'
;
import
{
Client
}
from
'
../../../../services/api
'
;
...
...
@@ -13,6 +12,8 @@ import { Session } from '../../../../services/session';
import
{
ActivatedRoute
}
from
'
@angular/router
'
;
import
{
of
}
from
'
rxjs/internal/observable/of
'
;
import
{
FeedsService
}
from
'
../../../../common/services/feeds.service
'
;
import
{
feedsServiceMock
}
from
'
../../../../../tests/feed-service-mock.spec
'
;
import
{
BehaviorSubject
}
from
'
rxjs
'
;
describe
(
'
BoostConsoleBooster
'
,
()
=>
{
...
...
@@ -41,28 +42,8 @@ describe('BoostConsoleBooster', () => {
beforeEach
((
done
)
=>
{
jasmine
.
MAX_PRETTY_PRINT_DEPTH
=
2
;
fixture
=
TestBed
.
createComponent
(
BoostConsoleBooster
);
comp
=
fixture
.
componentInstance
;
// feedsService.response = {};
feedsServiceMock
.
response
[
'
api/v1/newsfeed/personal
'
]
=
{
status
:
'
success
'
,
activity
:
[
{
guid
:
'
123
'
},
{
guid
:
'
456
'
},
]
};
feedsServiceMock
.
response
[
'
api/v1/entities/owner
'
]
=
{
status
:
'
success
'
,
entities
:
[
{
guid
:
'
789
'
},
{
guid
:
'
101112
'
},
]
};
fixture
.
detectChanges
();
if
(
fixture
.
isStable
())
{
...
...
@@ -77,7 +58,7 @@ describe('BoostConsoleBooster', () => {
});
it
(
'
should have loaded the lists
'
,
()
=>
{
expect
(
comp
.
feed$
).
toBeDefined
();
expect
(
comp
.
feed$
).
not
.
toBeFalsy
();
});
it
(
'
should have a title
'
,
()
=>
{
...
...
@@ -93,17 +74,31 @@ describe('BoostConsoleBooster', () => {
});
it
(
"
should have a poster if the user hasn't posted anything yet
"
,
()
=>
{
fixture
.
detectChanges
();
comp
.
posts
=
[];
comp
.
feed$
=
of
([]);
fixture
.
detectChanges
();
comp
.
feed$
.
subscribe
(
feed
=>
expect
(
feed
.
length
).
toBe
(
0
));
const
title
=
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-boost-console-booster--content h3
'
));
expect
(
title
).
not
.
toBeNull
();
expect
(
title
.
nativeElement
.
textContent
).
toContain
(
"
You have no content yet. Why don't you post something?
"
);
const
poster
=
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-boost-console-booster--content > div:nth-child(3)
'
));
expect
(
poster
).
not
.
toBeNull
();
expect
(
poster
.
nativeElement
.
hasAttribute
(
'
hidden
'
)).
toEqual
(
true
);
});
it
(
"
should not have a poster if the user has posted content
"
,
()
=>
{
comp
.
feed$
=
of
([
BehaviorSubject
.
create
({
id
:
1
}),
BehaviorSubject
.
create
({
id
:
2
})]);
fixture
.
detectChanges
();
comp
.
feed$
.
subscribe
(
feed
=>
expect
(
feed
.
length
).
toBe
(
2
));
const
title
=
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-boost-console-booster--content h3
'
));
expect
(
title
).
toBeDefined
();
expect
(
title
.
nativeElement
.
textContent
).
toContain
(
"
You have no content yet. Why don't you post something?
"
);
const
poster
=
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-boost-console-booster--content > div:nth-child(3)
'
));
expect
(
poster
).
toBeDefined
();
});
});
This diff is collapsed.
Click to expand it.
src/app/modules/boost/console/booster/booster.component.ts
View file @
3f7c0e7e
...
...
@@ -4,10 +4,12 @@ import { FeedsService } from '../../../../common/services/feeds.service';
import
{
BoostConsoleType
}
from
'
../console.component
'
;
import
{
Client
}
from
'
../../../../services/api
'
;
import
{
Session
}
from
'
../../../../services/session
'
;
import
{
PosterComponent
}
from
'
../../../newsfeed/poster/poster.component
'
;
import
{
merge
}
from
'
rxjs/operators
'
;
import
{
BehaviorSubject
,
Observable
}
from
'
rxjs
'
;
import
{
PosterComponent
}
from
'
../../../newsfeed/poster/poster.component
'
;
/**
* The component for the boost console.
*/
@
Component
({
moduleId
:
module
.
id
,
selector
:
'
m-boost-console-booster
'
,
...
...
@@ -15,42 +17,43 @@ import { BehaviorSubject, Observable } from 'rxjs';
})
export
class
BoostConsoleBooster
{
inProgress
:
boolean
=
false
;
loaded
:
boolean
=
fals
e
;
/* type of the feed to display */
@
Input
(
'
type
'
)
type
:
BoostConsoleTyp
e
;
posts
:
any
[]
=
[];
media
:
any
[]
=
[]
;
/* poster component */
@
ViewChild
(
'
poster
'
,
{
read
:
ViewContainerRef
,
static
:
false
})
poster
:
ViewContainerRef
;
inProgress
:
boolean
=
false
;
loaded
:
boolean
=
false
;
feed$
:
Observable
<
BehaviorSubject
<
Object
>
[]
>
;
componentRef
;
componentInstance
:
PosterComponent
;
@
Input
(
'
type
'
)
type
:
BoostConsoleType
;
@
ViewChild
(
'
poster
'
,
{
read
:
ViewContainerRef
,
static
:
false
})
poster
:
ViewContainerRef
;
noContent
:
boolean
=
true
;
constructor
(
public
client
:
Client
,
public
session
:
Session
,
private
route
:
ActivatedRoute
,
public
ownerFeedsService
:
FeedsService
,
public
personalFeedsService
:
FeedsService
,
private
_componentFactoryResolver
:
ComponentFactoryResolver
,
public
feedsService
:
FeedsService
,
private
cd
:
ChangeDetectorRef
,
private
componentFactoryResolver
:
ComponentFactoryResolver
,
)
{
}
/**
* subscribes to route parent url and loads component.
*/
ngOnInit
()
{
this
.
loaded
=
false
;
this
.
route
.
parent
.
url
.
subscribe
(
segments
=>
{
this
.
type
=
<
BoostConsoleType
>
segments
[
0
].
path
;
this
.
load
(
true
);
this
.
loaded
=
true
;
this
.
loadPoster
();
});
}
/**
* Loads the infinite feed
, merging two pipelines into on
e.
* Loads the infinite feed
for the respective parent rout
e.
* @param { boolean } refresh - is the state refreshing?
*/
load
(
refresh
?:
boolean
)
{
...
...
@@ -59,57 +62,36 @@ export class BoostConsoleBooster {
}
if
(
refresh
)
{
this
.
ownerFeedsService
.
clear
();
this
.
personalFeedsService
.
clear
();
this
.
feedsService
.
clear
();
}
this
.
inProgress
=
true
;
this
.
ownerFeedsService
.
setEndpoint
(
`api/v1/entities/owner`
)
.
setLimit
(
12
)
.
fetch
();
this
.
personalFeedsService
.
setEndpoint
(
'
api/v1/newsfeed/personal
'
)
this
.
feedsService
.
setEndpoint
(
this
.
type
===
'
content
'
?
'
api/v1/entities/owner
'
:
'
api/v1/newsfeed/personal
'
)
.
setLimit
(
12
)
.
fetch
();
this
.
feed$
=
this
.
ownerFeedsService
.
feed
.
pipe
(
merge
(
this
.
personalFeedsService
.
feed
)
);
this
.
feed$
=
this
.
feedsService
.
feed
;
this
.
inProgress
=
false
;
this
.
loaded
=
true
;
this
.
feed$
.
subscribe
(
feed
=>
this
.
noContent
=
feed
.
length
?
false
:
true
);
}
/**
* To be called by infinite-feed to load more data from two pipes.
*/
loadNext
()
{
this
.
loadFeed
(
this
.
ownerFeedsService
);
this
.
loadFeed
(
this
.
personalFeedsService
);
}
/**
* Reloads an individual feed.
* Loads next data in feed.
* @param feed - the feed to reload.
*/
load
Feed
(
feed
:
FeedsService
)
{
if
(
feed
.
canFetchMore
&&
!
feed
.
inProgress
.
getValue
()
&&
feed
.
offset
.
getValue
()
load
Next
(
)
{
if
(
this
.
feedsService
.
canFetchMore
&&
!
this
.
feedsService
.
inProgress
.
getValue
()
&&
this
.
feedsService
.
offset
.
getValue
()
)
{
feed
.
fetch
();
// load the next 150 in the background
this
.
feedsService
.
fetch
();
// load the next 150 in the background
}
feed
.
loadMore
();
}
/**
* If both have more data
*/
haveMoreData
()
{
return
((
!
this
.
ownerFeedsService
.
inProgress
&&
this
.
ownerFeedsService
.
hasMore
)
||
(
!
this
.
personalFeedsService
.
inProgress
&&
this
.
personalFeedsService
.
hasMore
));
this
.
feedsService
.
loadMore
();
}
/**
...
...
@@ -125,7 +107,32 @@ export class BoostConsoleBooster {
/**
* Detaches change detector on destroy
*/
ngOnDestroy
()
{
this
.
cd
.
detach
();
ngOnDestroy
=
()
=>
this
.
cd
.
detach
();
/**
* Loads the poster component if there are no activities loaded.
* @returns {boolean} success.
*/
loadPoster
()
{
this
.
feedsService
.
feed
.
subscribe
(
feed
=>
{
if
(
feed
.
length
>
0
)
{
try
{
this
.
poster
.
clear
();
this
.
componentRef
.
clear
();
this
.
noContent
=
true
;
return
false
;
}
catch
(
e
)
{
return
false
;
}
}
const
componentFactory
=
this
.
componentFactoryResolver
.
resolveComponentFactory
(
PosterComponent
);
this
.
componentRef
=
this
.
poster
.
createComponent
(
componentFactory
);
this
.
componentInstance
=
this
.
componentRef
.
instance
;
this
.
componentInstance
.
load
.
subscribe
(()
=>
{
this
.
load
();
});
return
true
;
});
}
}
This diff is collapsed.
Click to expand it.
src/tests/feed-service-mock.spec.ts
View file @
3f7c0e7e
...
...
@@ -7,7 +7,7 @@
import
{
BehaviorSubject
,
of
}
from
'
rxjs
'
;
export
let
feedsServiceMock
=
{
feed
:
new
BehaviorSubject
([
Promise
.
resolve
(
'
testing
'
)]),
feed
:
new
BehaviorSubject
([
Promise
.
resolve
(
'
[1,2,3,4,5]
'
)]),
clear
()
{
of
(
{
response
:
false
},
{
response
:
false
},
{
response
:
true
}
);
},
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment