Skip to content

Commit

Permalink
Merge pull request superdesk#122 from tomaskikutis/clear-filter-value…
Browse files Browse the repository at this point in the history
…s-upon-clicking-the-button
  • Loading branch information
tomaskikutis authored and MarkLark86 committed Apr 22, 2020
1 parent fee9a2d commit 32f8de4
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export function ContentPublishingReportController(
$interpolate,
reportConfigs
) {
function resetParams() {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
}

const reportName = 'content_publishing_report';

/**
Expand All @@ -70,6 +74,12 @@ export function ContentPublishingReportController(

this.chart = chartConfig.newConfig('chart', _.get($scope, 'currentParams.params.chart.type'));
$scope.updateChartConfig();

document.addEventListener('sda-source-filters--clear', resetParams);

$scope.$on('$destroy', () => {
document.removeEventListener('sda-source-filters--clear', resetParams);
});
};

/**
Expand Down Expand Up @@ -199,7 +209,7 @@ export function ContentPublishingReportController(
if (_.get(newReport, '_id')) {
$scope.currentParams = _.cloneDeep(savedReports.currentReport);
} else {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
resetParams();
}
}, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export function DeskActivityReportController(
desks,
reportConfigs
) {
function resetParams() {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
}

const reportName = 'desk_activity_report';

/**
Expand Down Expand Up @@ -97,6 +101,12 @@ export function DeskActivityReportController(
'states',
'ingest_providers',
];

document.addEventListener('sda-source-filters--clear', resetParams);

$scope.$on('$destroy', () => {
document.removeEventListener('sda-source-filters--clear', resetParams);
});
};

this.updateConfig = () => {
Expand Down Expand Up @@ -250,7 +260,7 @@ export function DeskActivityReportController(
if (_.get(newReport, '_id')) {
$scope.currentParams = _.cloneDeep(savedReports.currentReport);
} else {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
resetParams();
}

$scope.updateChartConfig();
Expand Down
2 changes: 2 additions & 0 deletions client/directives/AnalyticsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ export function AnalyticsContainer() {

$scope.onClearFilters = () => {
$scope.changeReportParams();

document.dispatchEvent(new Event('sda-source-filters--clear'));
};

$scope.beforeGenerateChart = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export function FeaturemediaUpdatesReportController(
chartConfig,
reportConfigs
) {
function resetParams() {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
}

const reportName = 'featuremedia_updates_report';

/**
Expand All @@ -74,6 +78,12 @@ export function FeaturemediaUpdatesReportController(

this.chart = chartConfig.newConfig('chart', 'table');
$scope.updateChartConfig();

document.addEventListener('sda-source-filters--clear', resetParams);

$scope.$on('$destroy', () => {
document.removeEventListener('sda-source-filters--clear', resetParams);
});
};

/**
Expand Down Expand Up @@ -157,7 +167,7 @@ export function FeaturemediaUpdatesReportController(
if (_.get(newReport, '_id')) {
$scope.currentParams = _.cloneDeep(savedReports.currentReport);
} else {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
resetParams();
}
}, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export function PlanningUsageReportController(
$q,
reportConfigs
) {
function resetParams() {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
}

const reportName = 'planning_usage_report';

/**
Expand Down Expand Up @@ -86,6 +90,12 @@ export function PlanningUsageReportController(

this.chart = chartConfig.newConfig(reportName, 'bar');
$scope.updateChartConfig();

document.addEventListener('sda-source-filters--clear', resetParams);

$scope.$on('$destroy', () => {
document.removeEventListener('sda-source-filters--clear', resetParams);
});
};

/**
Expand Down Expand Up @@ -162,7 +172,7 @@ export function PlanningUsageReportController(
if (_.get(newReport, '_id')) {
$scope.currentParams = _.cloneDeep(savedReports.currentReport);
} else {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
resetParams();
}
}, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export function ProductionTimeReportController(
$q,
reportConfigs
) {
function resetParams() {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
}

const reportName = 'production_time_report';

/**
Expand Down Expand Up @@ -91,6 +95,12 @@ export function ProductionTimeReportController(
SOURCE_FILTERS.STATS.DESK_TRANSITIONS.ENTER,
SOURCE_FILTERS.STATS.DESK_TRANSITIONS.EXIT,
];

document.addEventListener('sda-source-filters--clear', resetParams);

$scope.$on('$destroy', () => {
document.removeEventListener('sda-source-filters--clear', resetParams);
});
};

/**
Expand Down Expand Up @@ -193,7 +203,7 @@ export function ProductionTimeReportController(
if (_.get(newReport, '_id')) {
$scope.currentParams = _.cloneDeep(savedReports.currentReport);
} else {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
resetParams();
}

$scope.updateChartConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export function PublishingPerformanceReportController(
$interpolate,
reportConfigs
) {
function resetParams() {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
}

const reportName = 'publishing_performance_report';

/**
Expand Down Expand Up @@ -78,6 +82,12 @@ export function PublishingPerformanceReportController(

this.chart = chartConfig.newConfig('chart', _.get($scope, 'currentParams.params.chart.type'));
$scope.updateChartConfig();

document.addEventListener('sda-source-filters--clear', resetParams);

$scope.$on('$destroy', () => {
document.removeEventListener('sda-source-filters--clear', resetParams);
});
};

/**
Expand Down Expand Up @@ -203,7 +213,7 @@ export function PublishingPerformanceReportController(
if (_.get(newReport, '_id')) {
$scope.currentParams = _.cloneDeep(savedReports.currentReport);
} else {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
resetParams();
}
}, true);

Expand Down
2 changes: 1 addition & 1 deletion client/saved_reports/views/save-generate-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ng-click="clearFilters()"
ng-disabled="!isDirty()"
translate
>Clear Filters</button>
>Reset Filters</button>
<button class="btn btn--primary"
ng-click="generateReport()"
translate
Expand Down
14 changes: 14 additions & 0 deletions client/search/directives/SourceFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ export function SourceFilters(
paddingBottom: '=?',
},
link: function(scope) {
function clearFilters() {
Object.keys(scope.filters).forEach((key) => {
const filter = scope.filters[key];

filter.selected = [];
filter.exclude = false;
});
}
/**
* @ngdoc method
* @name SourceFilters#init
Expand Down Expand Up @@ -228,6 +236,8 @@ export function SourceFilters(
});

scope.flags.ready = true;

document.addEventListener('sda-source-filters--clear', clearFilters);
});
};

Expand Down Expand Up @@ -554,6 +564,10 @@ export function SourceFilters(
};

this.init();

scope.$on('$destroy', () => {
document.removeEventListener('sda-source-filters--clear', clearFilters);
});
},
};
}
2 changes: 1 addition & 1 deletion client/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as directives from './directives';
angular.module('superdesk.analytics.search', [])
.service('searchReport', svc.SearchReport)

.directive('sdaSourceFilters', directives.SourceFilters)
.directive('sdaSourceFilters', directives.SourceFilters) // !!! used in superdesk-aap project
.directive('sdaDateFilters', directives.DateFilters)

.directive('sdaPreviewDateFilter', directives.PreviewDateFilter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export function UpdateTimeReportController(
chartConfig,
reportConfigs
) {
function resetParams() {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
}

const reportName = 'update_time_report';

/**
Expand Down Expand Up @@ -85,6 +89,12 @@ export function UpdateTimeReportController(

this.chart = chartConfig.newConfig('chart', 'table');
$scope.updateChartConfig();

document.addEventListener('sda-source-filters--clear', resetParams);

$scope.$on('$destroy', () => {
document.removeEventListener('sda-source-filters--clear', resetParams);
});
};

/**
Expand Down Expand Up @@ -176,7 +186,7 @@ export function UpdateTimeReportController(
if (_.get(newReport, '_id')) {
$scope.currentParams = _.cloneDeep(savedReports.currentReport);
} else {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
resetParams();
}
}, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export function UserActivityReportController(
$compile,
reportConfigs
) {
function resetParams() {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
}

const reportName = 'user_activity_report';

/**
Expand Down Expand Up @@ -103,6 +107,12 @@ export function UserActivityReportController(

$scope.translatedOperations = getTranslatedOperations(gettext);
$scope.selectedItem = null;

document.addEventListener('sda-source-filters--clear', resetParams);

$scope.$on('$destroy', () => {
document.removeEventListener('sda-source-filters--clear', resetParams);
});
};

/**
Expand Down Expand Up @@ -204,7 +214,7 @@ export function UserActivityReportController(
if (_.get(newReport, '_id')) {
$scope.currentParams = _.cloneDeep(savedReports.currentReport);
} else {
$scope.currentParams = _.cloneDeep($scope.defaultReportParams);
resetParams();
}

$scope.updateChartConfig();
Expand Down

0 comments on commit 32f8de4

Please sign in to comment.