<commit_before>import _ from "lodash";
import {combineFlowData, enrichConsumes} from "../../utilities";
import {initialiseData, mkEntityLinkGridCell, mkLinkGridCell, termSearch} from "../../../common";


const bindings = {
    physicalFlows: '<',
    specifications: '<',
    onInitialise: '<',
    onChange: '<'
};


const initialState = {
    physicalFlows: [],
    specifications: [],
    onInitialise: (e) => {},
    onChange: (e) => {}
};


const template = require('./physical-data-section.html');


function mkData(specifications = { produces: [], consumes: [] },
                physicalFlows = [])
{

    const ownedData = combineFlowData(
        specifications.produces,
        physicalFlows);

    const produces = _.filter(ownedData, p => p.physicalFlow != null);

    const consumes = enrichConsumes(
        specifications.consumes,
        physicalFlows);

    const unusedSpecifications = _.chain(ownedData)
        .filter(p => !p.physicalFlow)
        .map('specification')
        .value();

    return { produces, consumes, unusedSpecifications };
}


function controller() {

    const vm = initialiseData(this, initialState);

    vm.produceColumnDefs = [
        Object.assign(mkLinkGridCell('Name', 'specification.name', 'physicalFlow.id', 'main.physical-flow.view'), { width: "20%"} ),
        { field: 'specification.externalId', displayName: 'Ext. Id', width: "8%" },
        Object.assign(mkEntityLinkGridCell('Receiver(s)', 'targetRef', 'left'), { width: "15%" }),
        { field: 'specification.format', displayName: 'Format', width: "8%" },
        { field: 'physicalFlow.transport', displayName: 'Transport', width: "10%" },
        { field: 'physicalFlow.frequency', displayName: 'Frequency', width: "9%" },
        { field: 'specification.description', displayName: 'Description', width: "30%" }
    ];

    vm.consumeColumnDefs = [
        Object.assign(mkEntityLinkGridCell('Source Application', 'sourceRef', 'none'), { width: "15%"} ),
        Object.assign(mkLinkGridCell('Name', 'specification.name', 'specification.id', 'main.physical-specification.view'), { width: "20%"} ),
        { field: 'specification.externalId', displayName: 'Ext. Id', width: "10%" },
        { field: 'specification.format', displayName: 'Format', width: "8%" },
        { field: 'physicalFlow.transport', displayName: 'Transport', width: "14%" },
        { field: 'physicalFlow.frequency', displayName: 'Frequency', width: "10%" },
        { field: 'specification.description', displayName: 'Description', width: "23%" }
    ];

    vm.unusedSpecificationsColumnDefs = [
        { field: 'name', displayName: 'Name' },
        { field: 'format', displayName: 'Format' },
        { field: 'description', displayName: 'Description' }
    ];

    const produceFields = _.map(vm.produceColumnDefs, 'field');

    const consumeFields = _.map(vm.consumeColumnDefs, 'field');

    vm.$onChanges = (changes) => {
        Object.assign(vm, mkData(vm.specifications, vm.physicalFlows));
        vm.filterProduces("");
        vm.filterConsumes("");
    };

    function notifyChange() {
        // callback
        vm.onChange({
            producesCount: vm.filteredProduces ? vm.filteredProduces.length : 0,
            consumesCount: vm.filteredConsumes ? vm.filteredConsumes.length : 0,
            unusedSpecificationsCount: vm.unusedSpecifications ? vm.unusedSpecifications.length : 0
        });
    }

    vm.filterProduces = (query) => {
        vm.filteredProduces = termSearch(vm.produces, query, produceFields);
        notifyChange();<commit_msg>AppView: phys specs / consumes link goes to wrong page<commit_after>import _ from "lodash";
import {combineFlowData, enrichConsumes} from "../../utilities";
import {initialiseData, mkEntityLinkGridCell, mkLinkGridCell, termSearch} from "../../../common";


const bindings = {
    physicalFlows: '<',
    specifications: '<',
    onInitialise: '<',
    onChange: '<'
};


const initialState = {
    physicalFlows: [],
    specifications: [],
    onInitialise: (e) => {},
    onChange: (e) => {}
};


const template = require('./physical-data-section.html');


function mkData(specifications = { produces: [], consumes: [] },
                physicalFlows = [])
{

    const ownedData = combineFlowData(
        specifications.produces,
        physicalFlows);

    const produces = _.filter(ownedData, p => p.physicalFlow != null);

    const consumes = enrichConsumes(
        specifications.consumes,
        physicalFlows);

    const unusedSpecifications = _.chain(ownedData)
        .filter(p => !p.physicalFlow)
        .map('specification')
        .value();

    return { produces, consumes, unusedSpecifications };
}


function controller() {

    const vm = initialiseData(this, initialState);

    vm.produceColumnDefs = [
        Object.assign(mkLinkGridCell('Name', 'specification.name', 'physicalFlow.id', 'main.physical-flow.view'), { width: "20%"} ),
        { field: 'specification.externalId', displayName: 'Ext. Id', width: "8%" },
        Object.assign(mkEntityLinkGridCell('Receiver(s)', 'targetRef', 'left'), { width: "15%" }),
        { field: 'specification.format', displayName: 'Format', width: "8%" },
        { field: 'physicalFlow.transport', displayName: 'Transport', width: "10%" },
        { field: 'physicalFlow.frequency', displayName: 'Frequency', width: "9%" },
        { field: 'specification.description', displayName: 'Description', width: "30%" }
    ];

    vm.consumeColumnDefs = [
        Object.assign(mkEntityLinkGridCell('Source Application', 'sourceRef', 'none'), { width: "15%"} ),
        Object.assign(mkLinkGridCell('Name', 'specification.name', 'physicalFlow.id', 'main.physical-flow.view'), { width: "20%"} ),
        { field: 'specification.externalId', displayName: 'Ext. Id', width: "10%" },
        { field: 'specification.format', displayName: 'Format', width: "8%" },
        { field: 'physicalFlow.transport', displayName: 'Transport', width: "14%" },
        { field: 'physicalFlow.frequency', displayName: 'Frequency', width: "10%" },
        { field: 'specification.description', displayName: 'Description', width: "23%" }
    ];

    vm.unusedSpecificationsColumnDefs = [
        { field: 'name', displayName: 'Name' },
        { field: 'format', displayName: 'Format' },
        { field: 'description', displayName: 'Description' }
    ];

    const produceFields = _.map(vm.produceColumnDefs, 'field');

    const consumeFields = _.map(vm.consumeColumnDefs, 'field');

    vm.$onChanges = (changes) => {
        Object.assign(vm, mkData(vm.specifications, vm.physicalFlows));
        vm.filterProduces("");
        vm.filterConsumes("");
    };

    function notifyChange() {
        // callback
        vm.onChange({
            producesCount: _.size(vm.filteredProduces),
            consumesCount: _.size(vm.filteredConsumes),
            unusedSpecificationsCount: _.size(vm.unusedSpecifications)
        });
    }

    vm.filterProduces = (query) => {
        vm.filteredProduces = termSearch(vm.produces, query, produceFields);
        notifyChange();
{'fraction_non_alphanumeric': 0.1622955442752397, 'fraction_numerical': 0.0071912013536379014, 'mean_word_length': 3.278045838359469, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '424848', 'n_tokens_mistral': 2145, 'n_tokens_neox': 2041, 'n_words': 417}