import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Colors, IconButton } from 'browndash-components'; import { action, makeObservable, observable } from 'mobx'; import { observer } from 'mobx-react'; import React from 'react'; import { Doc } from '../../../../fields/Doc'; import { Docs } from '../../../documents/Documents'; import { DocumentType } from '../../../documents/DocumentTypes'; import { ViewBoxBaseComponent } from '../../DocComponent'; import { FieldView, FieldViewProps } from '../../nodes/FieldView'; import { MarqueeOptionsMenu } from './MarqueeOptionsMenu'; import './ImageLabelBox.scss'; import { MainView } from '../../MainView'; import { MarqueeView } from './MarqueeView'; import 'ldrs/ring'; import { ring } from 'ldrs'; import { SnappingManager } from '../../../util/SnappingManager'; import { ImageCast } from '../../../../fields/Types'; import { DocData } from '../../../../fields/DocSymbols'; @observer export class ImageLabelBox extends ViewBoxBaseComponent() { public static LayoutString(fieldKey: string) { return FieldView.LayoutString(ImageLabelBox, fieldKey); } public static Instance: ImageLabelBox | null = null; private _inputRef = React.createRef(); @observable _loading: boolean = true; @observable _currentLabel: string = ''; @observable _labelGroups: string[] = []; @observable _selectedImages: Doc[] = []; @observable _displayImageInformation: boolean = false; constructor(props: any) { super(props); makeObservable(this); ImageLabelBox.Instance = this; ring.register(); console.log('Image Box Has Been Initialized'); } /** * This method is called when the SearchBox component is first mounted. When the user opens * the search panel, the search input box is automatically selected. This allows the user to * type in the search input box immediately, without needing clicking on it first. */ componentDidMount() { // if (this._inputRef.current) { // this._inputRef.current.focus(); // } } @action addLabel = (label: string) => { label = label.toUpperCase().trim(); if (label.length > 0) { if (!this._labelGroups.includes(label)) { this._labelGroups = [...this._labelGroups, label]; } } }; @action removeLabel = (label: string) => { const labelUp = label.toUpperCase(); this._labelGroups = this._labelGroups.filter(group => group !== labelUp); }; @action groupImages = () => { MarqueeOptionsMenu.Instance.groupImages(); this._labelGroups = []; MainView.Instance.closeFlyout(); }; @action startLoading = () => { this._loading = true; }; @action endLoading = () => { this._loading = false; }; @action setSelectedImages = (selected: Doc[]) => { this._selectedImages = selected; }; render() { if (this._loading) { return (
); } return (
{ this._displayImageInformation = !this._displayImageInformation; }} icon={this._displayImageInformation ? : } color={MarqueeOptionsMenu.Instance.userColor} style={{ width: '19px' }} /> { // e.key === 'Enter' ? this.submitSearch() : null; // e.stopPropagation(); // }} type="text" placeholder="Input labels for image groupings..." aria-label="label-input" id="new-label" className="searchBox-input" style={{ width: '100%', borderRadius: '5px' }} ref={this._inputRef} /> { const input = document.getElementById('new-label') as HTMLInputElement; const newLabel = input.value; this.addLabel(newLabel); this._currentLabel = ''; input.value = ''; }} icon={} color={MarqueeOptionsMenu.Instance.userColor} style={{ width: '19px' }} /> {this._labelGroups.length > 0 ? } color={Colors.MEDIUM_BLUE} style={{ width: '19px' }} /> :
}
{this._labelGroups.map(group => { return (

{group}

{ this.removeLabel(group); }} icon={'x'} color={MarqueeOptionsMenu.Instance.userColor} style={{ width: '8px' }} />
); })}
{this._displayImageInformation ? (
{this._selectedImages.map(doc => { const [name, type] = ImageCast(doc[Doc.LayoutFieldKey(doc)]).url.href.split('.'); return (
{(doc[DocData].data_labels as string).split('\n').map(label => { return
{label}
; })}
); })}
) : (
)}
); } } Docs.Prototypes.TemplateMap.set(DocumentType.IMAGEGROUPER, { layout: { view: ImageLabelBox, dataField: 'data' }, options: { acl: '', _width: 400 }, });