Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search: add tooltip on delete button of brief view #288

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/ng-core-tester/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const permissions = (record: any) => {
}),
canDelete: of({
can: perms.delete,
message: ''
message: 'This record cannot be deleted.'
})
};
};
Expand Down
2 changes: 2 additions & 0 deletions projects/rero/ng-core/src/lib/record/record.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { NgxBootstrapSliderModule } from 'ngx-bootstrap-slider';
import { CollapseModule } from 'ngx-bootstrap/collapse';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { PaginationModule } from 'ngx-bootstrap/pagination';
import { PopoverModule } from 'ngx-bootstrap/popover';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { TypeaheadModule } from 'ngx-bootstrap/typeahead';
import { CoreModule } from '../core.module';
Expand Down Expand Up @@ -98,6 +99,7 @@ import { RecordSearchResultDirective } from './search/result/record-search-resul
ReactiveFormsModule,
RecordRoutingModule,
TooltipModule.forRoot(),
PopoverModule.forRoot(),
TypeaheadModule.forRoot(),
PaginationModule.forRoot(),
CollapseModule.forRoot(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@
<i class="fa fa-trash"></i>
</button>
<ng-template #deleteMessageLink>
<button id="result-delete-button"
disabled
class="btn btn-sm btn-outline-danger"
<button *ngIf="deleteStatus.message"
id="result-delete-button"
class="btn btn-sm btn-outline-danger disabled"
[title]="'Delete'|translate"
[name]="'Delete'|translate"
(click)="showDeleteMessage(deleteStatus.message)" *ngIf="deleteStatus.message">
[popover]="tolTemplate" triggers="mouseenter:mouseleave">
<i class="fa fa-trash"></i>
</button>
</ng-template>
<ng-template #tolTemplate>
<div [innerHtml]="deleteInfoMessage | nl2br"></div>
</ng-template>
</span>
</div>
<ng-template ngCoreRecordSearchResult></ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/t
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { ModalModule } from 'ngx-bootstrap/modal';
import { PopoverModule } from 'ngx-bootstrap/popover';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { ToastrModule } from 'ngx-toastr';
import { CoreModule } from '../../../core.module';
import { JsonComponent } from './item/json.component';
import { RecordSearchResultComponent } from './record-search-result.component';
import { RecordSearchResultDirective } from './record-search-result.directive';
Expand All @@ -44,7 +47,10 @@ describe('RecordSearchResultComponent', () => {
loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
}),
ToastrModule.forRoot(),
HttpClientModule
HttpClientModule,
TooltipModule.forRoot(),
PopoverModule.forRoot(),
CoreModule
],
schemas: [ NO_ERRORS_SCHEMA ]
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, ComponentFactoryResolver, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { ActionStatus } from '../../action-status';
import { RecordUiService } from '../../record-ui.service';
import { JsonComponent } from './item/json.component';
import { ResultItem } from './item/result-item';
import { RecordSearchResultDirective } from './record-search-result.directive';
import { Router} from '@angular/router';


@Component({
Expand Down Expand Up @@ -121,16 +120,22 @@ export class RecordSearchResultComponent implements OnInit {
*/
@ViewChild(RecordSearchResultDirective, { static: true }) searchResultItem: RecordSearchResultDirective;


/**
* Return a message containing the reasons why the item cannot be deleted
*/
get deleteInfoMessage(): string {
return this.deleteStatus.message;
}

/**
* Constructor.
*
* @param _componentFactoryResolver Component factory resolver.
* @param _recordUiService Record UI service.
* @param _router: Router
*/
constructor(
private _componentFactoryResolver: ComponentFactoryResolver,
private _recordUiService: RecordUiService,
private _router: Router
) {
this.currentUrl = window.location.href;
Expand Down Expand Up @@ -204,12 +209,4 @@ export class RecordSearchResultComponent implements OnInit {
useRecord() {
this._router.navigateByUrl(this.useStatus.url);
}

/**
* Show dialog with the reason why record cannot be deleted.
* @param message - string, message to display
*/
showDeleteMessage(message: string) {
this._recordUiService.showDeleteMessage(message);
}
}