Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
urgi-is
data-discovery
Commits
92f60fe3
Verified
Commit
92f60fe3
authored
Jun 29, 2020
by
Exbrayat Cédric
Committed by
Raphaël Flores
Jul 31, 2020
Browse files
feat: add a configuration to disable the basket
parent
95ec457e
Changes
18
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
92f60fe3
...
...
@@ -131,17 +131,17 @@ or
```
sh
./gradlew assemble
-Papp
=
wheatis
```
which is a shortcut for
or
```
sh
./gradlew assemble
-Papp
=
wheatis
&&
java
-jar
path/to/wheatis.jar
./gradlew assemble
-Papp
=
rare-no-basket
```
This will build a standalone jar at
`backend/build/libs/`
, that you can run with either:
```
sh
java
-jar
backend/build/libs/rare.jar
java
-jar
backend/build/libs/rare-no-basket.jar
java
-jar
backend/build/libs/wheatis.jar
java
-jar
backend/build/libs/data-discovery.jar
```
...
...
buildSrc/src/main/kotlin/app.kt
View file @
92f60fe3
import
org.gradle.api.*
import
org.gradle.kotlin.dsl.*
private
val
acceptableValues
=
setOf
(
"rare"
,
"wheatis"
,
"data-discovery"
)
private
val
acceptableValues
=
setOf
(
"rare"
,
"rare-no-basket"
,
"wheatis"
,
"data-discovery"
)
val
Project
.
app
:
String
get
()
=
findProperty
(
"app"
)
...
...
frontend/angular.json
View file @
92f60fe3
...
...
@@ -116,6 +116,57 @@
}
]
},
"rare-no-basket"
:
{
"budgets"
:
[
{
"type"
:
"anyComponentStyle"
,
"maximumWarning"
:
"6kb"
}
],
"fileReplacements"
:
[
{
"replace"
:
"src/environments/environment.ts"
,
"with"
:
"src/environments/environment.rare.ts"
},
{
"replace"
:
"src/environments/rare-basket.ts"
,
"with"
:
"src/environments/no-basket.ts"
}
],
"baseHref"
:
"/rare-dev/"
},
"rare-no-basket-production"
:
{
"fileReplacements"
:
[
{
"replace"
:
"src/environments/environment.ts"
,
"with"
:
"src/environments/environment.rare.prod.ts"
},
{
"replace"
:
"src/environments/rare-basket.ts"
,
"with"
:
"src/environments/no-basket.ts"
}
],
"optimization"
:
true
,
"outputHashing"
:
"all"
,
"sourceMap"
:
false
,
"extractCss"
:
true
,
"namedChunks"
:
false
,
"aot"
:
true
,
"extractLicenses"
:
true
,
"vendorChunk"
:
false
,
"buildOptimizer"
:
true
,
"budgets"
:
[
{
"type"
:
"initial"
,
"maximumWarning"
:
"900kb"
,
"maximumError"
:
"1.2mb"
},
{
"type"
:
"anyComponentStyle"
,
"maximumWarning"
:
"6kb"
}
]
},
"wheatis"
:
{
"budgets"
:
[
{
...
...
@@ -264,6 +315,12 @@
"rare-production"
:
{
"browserTarget"
:
"data-discovery-frontend:build:rare-production"
},
"rare-no-basket"
:
{
"browserTarget"
:
"data-discovery-frontend:build:rare-no-basket"
},
"rare-no-basket-production"
:
{
"browserTarget"
:
"data-discovery-frontend:build:rare-no-basket-production"
},
"wheatis"
:
{
"browserTarget"
:
"data-discovery-frontend:build:wheatis"
},
...
...
frontend/package.json
View file @
92f60fe3
...
...
@@ -5,11 +5,13 @@
"ng"
:
"ng"
,
"start"
:
"ng serve --configuration=rare --port=4000"
,
"start:rare"
:
"ng serve --configuration=rare --port=4000"
,
"start:rare-no-basket"
:
"ng serve --configuration=rare-no-basket --port=4000"
,
"start:wheatis"
:
"ng serve --configuration=wheatis --port=4100"
,
"start:wheatis-production"
:
"ng serve --configuration=wheatis-production --port=4101"
,
"start:data-discovery"
:
"ng serve --configuration=data-discovery --port=4200"
,
"build"
:
"ng build --configuration=rare-production --no-progress"
,
"build:rare"
:
"ng build --configuration=rare-production --no-progress"
,
"build:rare-no-basket"
:
"ng build --configuration=rare-no-basket-production --no-progress"
,
"build:wheatis"
:
"ng build --configuration=wheatis-production --no-progress"
,
"build:data-discovery"
:
"ng build --configuration=data-discovery-production --no-progress"
,
"test"
:
"ng test --code-coverage --no-progress --no-watch"
,
...
...
frontend/src/app/documents/documents.component.html
View file @
92f60fe3
...
...
@@ -10,7 +10,7 @@
<span
translate=
"documents.results-limited"
[translateParams]=
"{ total: documents.maxResults | number }"
></span>
</ng-container>
</div>
<div
class=
"select-all-rare-basket"
>
<div
class=
"select-all-rare-basket"
*ngIf=
"isBasketEnabled"
>
<!-- the following component will not be the same depending on the environment.resourceModule value -->
<!-- for example, if the module is `RareModule` it will be a `RareSelectAllResultsComponent` -->
<!-- For others it will be an empty component -->
...
...
frontend/src/app/documents/documents.component.spec.ts
View file @
92f60fe3
...
...
@@ -37,7 +37,8 @@ describe('DocumentsComponent', () => {
}
}
const
basketService
=
jasmine
.
createSpyObj
<
BasketService
>
(
'
BasketService
'
,
[
'
isAccessionInBasket
'
]);
const
basketService
=
jasmine
.
createSpyObj
<
BasketService
>
(
'
BasketService
'
,
[
'
isEnabled
'
,
'
isAccessionInBasket
'
]);
basketService
.
isEnabled
.
and
.
returnValue
(
true
);
basketService
.
isAccessionInBasket
.
and
.
returnValue
(
of
(
false
));
beforeEach
(()
=>
{
...
...
frontend/src/app/documents/documents.component.ts
View file @
92f60fe3
...
...
@@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import
{
Page
}
from
'
../models/page
'
;
import
{
DocumentModel
}
from
'
../models/document.model
'
;
import
{
BasketService
}
from
'
../rare/basket.service
'
;
@
Component
({
selector
:
'
dd-documents
'
,
...
...
@@ -12,6 +13,11 @@ import { DocumentModel } from '../models/document.model';
export
class
DocumentsComponent
{
@
Input
()
documents
:
Page
<
DocumentModel
>
;
isBasketEnabled
:
boolean
;
constructor
(
basketService
:
BasketService
)
{
this
.
isBasketEnabled
=
basketService
.
isEnabled
();
}
get
firstResultIndex
()
{
return
(
this
.
documents
.
number
*
this
.
documents
.
size
)
+
1
;
...
...
frontend/src/app/rare/basket.service.ts
View file @
92f60fe3
...
...
@@ -48,6 +48,10 @@ export class BasketService {
this
.
restoreBasketFromLocalStorage
();
}
isEnabled
()
{
return
rareBasket
.
isBasketEnabled
;
}
restoreBasketFromLocalStorage
()
{
const
rareBasketStringified
=
window
.
localStorage
.
getItem
(
'
rare-basket
'
);
if
(
rareBasketStringified
)
{
...
...
frontend/src/app/rare/rare-basket/rare-basket.component.html
View file @
92f60fe3
<div
class=
"basket-counter navbar-text"
*ngIf=
"itemCounter === 0
; else navbarButton
"
>
<div
class=
"basket-counter navbar-text"
*ngIf=
"
isEnabled &&
itemCounter === 0"
>
<span
class=
"fa fa-fw fa-shopping-basket"
></span>
&ngsp;
<span
class=
"badge badge-pill badge-light"
>
0
</span>
</div>
<ng-template
#navbarButton
>
<button
class=
"basket-counter btn"
[ngbTooltip]=
"buttonTooltip"
(click)=
"viewItems(basketModal)"
>
<span
class=
"fa fa-fw fa-shopping-basket"
></span>
&ngsp;
<span
class=
"badge badge-pill badge-light"
>
{{ itemCounter | number }}
</span>
</button>
</ng-template>
<button
class=
"basket-counter btn"
*ngIf=
"isEnabled && itemCounter"
[ngbTooltip]=
"buttonTooltip"
(click)=
"viewItems(basketModal)"
>
<span
class=
"fa fa-fw fa-shopping-basket"
></span>
&ngsp;
<span
class=
"badge badge-pill badge-light"
>
{{ itemCounter | number }}
</span>
</button>
<ng-template
#buttonTooltip
>
<ng-container
[ngPlural]=
"itemCounter"
>
...
...
frontend/src/app/rare/rare-basket/rare-basket.component.spec.ts
View file @
92f60fe3
...
...
@@ -74,7 +74,8 @@ describe('RareBasketComponent', () => {
const
basketEvents
=
new
Subject
<
Basket
>
();
beforeEach
(()
=>
{
service
=
jasmine
.
createSpyObj
<
BasketService
>
(
'
BasketService
'
,
[
'
getBasket
'
,
'
removeFromBasket
'
,
'
sendBasket
'
,
'
clearBasket
'
]);
service
=
jasmine
.
createSpyObj
<
BasketService
>
(
'
BasketService
'
,
[
'
isEnabled
'
,
'
getBasket
'
,
'
removeFromBasket
'
,
'
sendBasket
'
,
'
clearBasket
'
]);
service
.
isEnabled
.
and
.
returnValue
(
true
);
service
.
getBasket
.
and
.
returnValue
(
basketEvents
);
location
=
jasmine
.
createSpyObj
<
Location
>
(
'
Location
'
,
[
'
assign
'
]);
TestBed
.
configureTestingModule
({
...
...
@@ -87,7 +88,6 @@ describe('RareBasketComponent', () => {
});
jasmine
.
addMatchers
(
speculoosMatchers
);
tester
=
new
RareBasketComponentTester
();
tester
.
detectChanges
();
});
afterEach
(()
=>
{
...
...
@@ -100,6 +100,7 @@ describe('RareBasketComponent', () => {
});
it
(
'
should display the number of items
'
,
()
=>
{
tester
.
detectChanges
();
// no item
expect
(
tester
.
basketCounterAsText
).
toContainText
(
'
0
'
);
...
...
@@ -139,6 +140,7 @@ describe('RareBasketComponent', () => {
});
it
(
'
should open a summary modal on click
'
,
()
=>
{
tester
.
detectChanges
();
basketEvents
.
next
({
items
:
[{
accession
:
{
identifier
:
'
rosa
'
,
name
:
'
Rosa
'
}
}
as
BasketItem
]
});
tester
.
detectChanges
();
tester
.
basketCounter
.
click
();
...
...
@@ -159,6 +161,7 @@ describe('RareBasketComponent', () => {
});
it
(
'
should send the basket
'
,
fakeAsync
(()
=>
{
tester
.
detectChanges
();
const
reference
=
'
ABCDEFGH
'
;
service
.
sendBasket
.
and
.
returnValue
(
of
({
...
...
@@ -187,6 +190,7 @@ describe('RareBasketComponent', () => {
}));
it
(
'
should clear the basket
'
,
()
=>
{
tester
.
detectChanges
();
basketEvents
.
next
({
items
:
[{
accession
:
{
identifier
:
'
rosa
'
,
name
:
'
Rosa
'
}
}
as
BasketItem
]
});
tester
.
detectChanges
();
tester
.
basketCounter
.
click
();
...
...
@@ -194,4 +198,11 @@ describe('RareBasketComponent', () => {
tester
.
clearBasket
.
click
();
expect
(
service
.
clearBasket
).
toHaveBeenCalled
();
});
it
(
'
should not display if the basket feature is disabled
'
,
()
=>
{
service
.
isEnabled
.
and
.
returnValue
(
false
);
tester
.
detectChanges
();
expect
(
tester
.
basketCounter
).
toBeNull
();
expect
(
tester
.
basketCounterAsText
).
toBeNull
();
});
});
frontend/src/app/rare/rare-basket/rare-basket.component.ts
View file @
92f60fe3
...
...
@@ -21,6 +21,7 @@ export class RareBasketComponent implements OnInit {
eulaAgreementControl
:
FormControl
;
submitted
=
false
;
confirmForbidden
=
false
;
isEnabled
:
boolean
;
constructor
(
private
basketService
:
BasketService
,
...
...
@@ -30,11 +31,14 @@ export class RareBasketComponent implements OnInit {
)
{}
ngOnInit
():
void
{
this
.
basketService
.
getBasket
().
subscribe
((
basket
:
Basket
)
=>
{
this
.
itemCounter
=
basket
.
items
.
length
;
this
.
basket
=
basket
;
});
this
.
eulaAgreementControl
=
this
.
fb
.
control
(
false
,
Validators
.
requiredTrue
);
this
.
isEnabled
=
this
.
basketService
.
isEnabled
();
if
(
this
.
isEnabled
)
{
this
.
basketService
.
getBasket
().
subscribe
((
basket
:
Basket
)
=>
{
this
.
itemCounter
=
basket
.
items
.
length
;
this
.
basket
=
basket
;
});
this
.
eulaAgreementControl
=
this
.
fb
.
control
(
false
,
Validators
.
requiredTrue
);
}
}
viewItems
(
basket
:
any
)
{
...
...
frontend/src/app/rare/rare-document/rare-document.component.html
View file @
92f60fe3
...
...
@@ -6,7 +6,7 @@
</a>
<small>
- {{ document.pillarName }}
</small>
&ngsp;
</div>
<div
*ngIf=
"document.accessionHolder"
>
<div
*ngIf=
"
isBasketEnabled &&
document.accessionHolder"
>
<button
*ngIf=
"!selectedForOrdering"
type=
"button"
...
...
frontend/src/app/rare/rare-document/rare-document.component.spec.ts
View file @
92f60fe3
...
...
@@ -64,16 +64,19 @@ describe('RareDocumentComponent', () => {
}
}
cons
t
basketService
=
jasmine
.
create
SpyObj
<
BasketService
>
(
'
BasketService
'
,
[
'
isAccessionInBasket
'
,
'
addToBasket
'
,
'
removeFromBasket
'
])
;
le
t
basketService
:
jasmine
.
SpyObj
<
BasketService
>
;
const
basketEvents
=
new
Subject
<
boolean
>
();
basketService
.
isAccessionInBasket
.
and
.
returnValue
(
basketEvents
);
beforeEach
(()
=>
beforeEach
(()
=>
{
basketService
=
jasmine
.
createSpyObj
<
BasketService
>
(
'
BasketService
'
,
[
'
isEnabled
'
,
'
isAccessionInBasket
'
,
'
addToBasket
'
,
'
removeFromBasket
'
]);
basketService
.
isEnabled
.
and
.
returnValue
(
true
);
basketService
.
isAccessionInBasket
.
and
.
returnValue
(
basketEvents
);
TestBed
.
configureTestingModule
({
imports
:
[
NgbTooltipModule
,
I18nTestingModule
],
declarations
:
[
RareDocumentComponent
,
TruncatableDescriptionComponent
],
providers
:
[{
provide
:
BasketService
,
useValue
:
basketService
}]
})
});
}
);
beforeEach
(()
=>
jasmine
.
addMatchers
(
speculoosMatchers
));
...
...
@@ -134,6 +137,18 @@ describe('RareDocumentComponent', () => {
expect
(
tester
.
type
).
toContainText
(
'
type1, type2
'
);
});
it
(
'
should not have the basket button if the feature is disabled
'
,
()
=>
{
basketService
.
isEnabled
.
and
.
returnValue
(
false
);
const
tester
=
new
RareDocumentComponentTester
();
const
component
=
tester
.
componentInstance
;
// given a resource with several types
component
.
document
=
toRareDocument
(
'
Bacteria
'
);
tester
.
detectChanges
();
// then the button should not be displayed
expect
(
tester
.
addToBasketButton
).
toBeNull
();
});
it
(
'
should add/remove to/from basket
'
,
()
=>
{
const
tester
=
new
RareDocumentComponentTester
();
const
component
=
tester
.
componentInstance
;
...
...
frontend/src/app/rare/rare-document/rare-document.component.ts
View file @
92f60fe3
...
...
@@ -11,14 +11,18 @@ import { BasketService } from '../basket.service';
export
class
RareDocumentComponent
implements
OnInit
{
selectedForOrdering
=
false
;
@
Input
()
document
:
RareDocumentModel
;
isBasketEnabled
:
boolean
;
constructor
(
private
changeDetectorRef
:
ChangeDetectorRef
,
private
basketService
:
BasketService
)
{}
ngOnInit
():
void
{
this
.
basketService
.
isAccessionInBasket
(
this
.
document
).
subscribe
(
isInBasket
=>
{
this
.
selectedForOrdering
=
isInBasket
;
this
.
changeDetectorRef
.
markForCheck
();
});
this
.
isBasketEnabled
=
this
.
basketService
.
isEnabled
();
if
(
this
.
isBasketEnabled
)
{
this
.
basketService
.
isAccessionInBasket
(
this
.
document
).
subscribe
(
isInBasket
=>
{
this
.
selectedForOrdering
=
isInBasket
;
this
.
changeDetectorRef
.
markForCheck
();
});
}
}
addToBasket
()
{
...
...
frontend/src/app/search/search.component.spec.ts
View file @
92f60fe3
...
...
@@ -55,7 +55,8 @@ class SearchComponentTester extends ComponentTester<SearchComponent> {
}
describe
(
'
SearchComponent
'
,
()
=>
{
const
basketService
=
jasmine
.
createSpyObj
<
BasketService
>
(
'
BasketService
'
,
[
'
isAccessionInBasket
'
]);
const
basketService
=
jasmine
.
createSpyObj
<
BasketService
>
(
'
BasketService
'
,
[
'
isEnabled
'
,
'
isAccessionInBasket
'
]);
basketService
.
isEnabled
.
and
.
returnValue
(
true
);
basketService
.
isAccessionInBasket
.
and
.
returnValue
(
of
(
false
));
beforeEach
(()
=>
TestBed
.
configureTestingModule
({
imports
:
[
...
...
frontend/src/environments/no-basket.ts
0 → 100644
View file @
92f60fe3
/**
* Configuration variables to disable RARe Basket.
* This file is only used by the RARe-no-basket version of the application.
* You NEVER have to import this version of the file:
* the build takes care of replacing it when needed.
*/
export
const
rareBasket
=
{
isBasketEnabled
:
false
,
url
:
'
http://localhost:4201/rare-basket
'
};
frontend/src/environments/rare-basket.prod.ts
View file @
92f60fe3
...
...
@@ -6,5 +6,6 @@
* See angular.json for more details.
*/
export
const
rareBasket
=
{
isBasketEnabled
:
true
,
url
:
'
http://localhost:4201/rare-basket
'
// TODO update to proper URL
};
frontend/src/environments/rare-basket.ts
View file @
92f60fe3
...
...
@@ -7,5 +7,6 @@
* the build takes care of replacing it by the production one.
*/
export
const
rareBasket
=
{
isBasketEnabled
:
true
,
url
:
'
http://localhost:4201/rare-basket
'
};
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