Skip to content

Commit

Permalink
Merge pull request #2985 from SEED-platform/refactor/analysis-propert…
Browse files Browse the repository at this point in the history
…y-display-field

Refactor/analysis property display field
  • Loading branch information
macintoshpie committed Nov 3, 2021
2 parents 7c8786c + bd90138 commit 4d16477
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 37 deletions.
Binary file modified locale/en_US/LC_MESSAGES/django.mo
Binary file not shown.
8 changes: 4 additions & 4 deletions locale/en_US/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1938,8 +1938,8 @@ msgstr "Property Detail Notes"
msgid "Property Detail Settings"
msgstr "Property Detail Settings"

msgid "Property Detail View Display Field"
msgstr "Property Detail View Display Field"
msgid "Property Display Field"
msgstr "Property Display Field"

msgid "Property Footprint"
msgstr "Property Footprint"
Expand Down Expand Up @@ -2400,8 +2400,8 @@ msgstr "Tax Lots"
msgid "Tax Lots List"
msgstr "Tax Lots List"

msgid "Taxlot Detail View Display Field"
msgstr "Taxlot Detail View Display Field"
msgid "Taxlot Display Field"
msgstr "Taxlot Display Field"

#: src/django-tos-master/tos/models.py:43
#: src/django-tos-master/tos/models.py:44
Expand Down
Binary file modified locale/fr_CA/LC_MESSAGES/django.mo
Binary file not shown.
8 changes: 4 additions & 4 deletions locale/fr_CA/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1953,8 +1953,8 @@ msgstr "Notes de détail de la propriété"
msgid "Property Detail Settings"
msgstr "Paramètres de détail de la propriété"

msgid "Property Detail View Display Field"
msgstr "Champ d'affichage de la vue détaillée de la propriété"
msgid "Property Display Field"
msgstr "Champ d'affichage de la propriété"

msgid "Property Footprint"
msgstr "Empreinte de propriété"
Expand Down Expand Up @@ -2420,8 +2420,8 @@ msgstr "Lots d'impôt"
msgid "Tax Lots List"
msgstr "Liste des lots d'impôt"

msgid "Taxlot Detail View Display Field"
msgstr "Champ d'affichage de la vue détaillée du lot de taxes"
msgid "Taxlot Display Field"
msgstr "Champ d'affichage du lot de taxes"

#: src/django-tos-master/tos/models.py:43
#: src/django-tos-master/tos/models.py:44
Expand Down
14 changes: 12 additions & 2 deletions seed/static/seed/js/controllers/analysis_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ angular.module('BE.seed.controller.analysis', [])
'$scope',
'$stateParams',
'$state',
'organization_service',
'analysis_payload',
'organization_payload',
'messages_payload',
Expand All @@ -18,6 +19,7 @@ angular.module('BE.seed.controller.analysis', [])
$scope,
$stateParams,
$state,
organization_service,
analysis_payload,
organization_payload,
messages_payload,
Expand All @@ -26,8 +28,7 @@ angular.module('BE.seed.controller.analysis', [])
auth_payload
) {
// WARNING: $scope.org is used by "child" controller - analysis_details_controller
$scope.org = organization_payload;
$scope.inventory_type = $stateParams.inventory_type;
$scope.org = organization_payload.organization;
$scope.auth = auth_payload.auth;
$scope.analysis = analysis_payload.analysis;
$scope.messages = messages_payload.messages;
Expand All @@ -42,4 +43,13 @@ angular.module('BE.seed.controller.analysis', [])
return true;
}
};

$scope.get_display_name = function (inventory_state) {
return organization_service.get_inventory_display_value(
$scope.org,
// NOTE: hardcoding 'property' b/c you can only run analyses on properties
'property',
inventory_state
);
};
}]);
13 changes: 12 additions & 1 deletion seed/static/seed/js/controllers/analysis_run_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ angular.module('BE.seed.controller.analysis_run', [])
'$scope',
'$stateParams',
'$state',
'organization_service',
'analysis_payload',
'organization_payload',
'messages_payload',
Expand All @@ -18,6 +19,7 @@ angular.module('BE.seed.controller.analysis_run', [])
$scope,
$stateParams,
$state,
organization_service,
analysis_payload,
organization_payload,
messages_payload,
Expand All @@ -26,7 +28,7 @@ angular.module('BE.seed.controller.analysis_run', [])
auth_payload
) {
// WARNING: $scope.org is used by "child" controller - analysis_details_controller
$scope.org = organization_payload;
$scope.org = organization_payload.organization;
$scope.auth = auth_payload.auth;
$scope.analysis = analysis_payload.analysis;
$scope.messages = messages_payload.messages;
Expand All @@ -49,4 +51,13 @@ angular.module('BE.seed.controller.analysis_run', [])
return true;
}
};

$scope.get_display_name = function (inventory_state) {
return organization_service.get_inventory_display_value(
$scope.org,
// NOTE: hardcoding 'property' b/c you can only run analyses on properties
'property',
inventory_state
)
};
}]);
21 changes: 8 additions & 13 deletions seed/static/seed/js/controllers/inventory_detail_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ angular.module('BE.seed.controller.inventory_detail', [])
'matching_service',
'pairing_service',
'derived_columns_service',
'organization_service',
'inventory_payload',
'analyses_payload',
'users_payload',
Expand Down Expand Up @@ -52,6 +53,7 @@ angular.module('BE.seed.controller.inventory_detail', [])
matching_service,
pairing_service,
derived_columns_service,
organization_service,
inventory_payload,
analyses_payload,
users_payload,
Expand Down Expand Up @@ -87,6 +89,12 @@ angular.module('BE.seed.controller.inventory_detail', [])
// stores derived column values -- updated later once we fetch the data
$scope.item_derived_values = {};

$scope.inventory_display_name = organization_service.get_inventory_display_value(
$scope.organization,
$scope.inventory_type === 'properties' ? 'property' : 'taxlot',
$scope.item_state
);

// item_parent is the property or the tax lot instead of the PropertyState / TaxLotState
if ($scope.inventory_type === 'properties') {
$scope.item_parent = inventory_payload.property;
Expand Down Expand Up @@ -736,19 +744,6 @@ angular.module('BE.seed.controller.inventory_detail', [])
return value;
};

$scope.inventory_display_name = function (property_type) {
let error = '';
let field = property_type == 'property' ? $scope.organization.property_display_field : $scope.organization.taxlot_display_field;
if (!(field in $scope.item_state)) {
error = field + ' does not exist';
field = 'address_line_1';
}
if (!$scope.item_state[field]) {
error += (error == '' ? '' : ' and default ') + field + ' is blank';
}
$scope.inventory_name = $scope.item_state[field] ? $scope.item_state[field] : '(' + error + ') <i class="glyphicon glyphicon-question-sign" title="This can be changed from the organization settings page."></i>';
};

// evaluate all derived columns and store the results
var evaluate_derived_columns = function () {
const visible_derived_columns = $scope.columns.filter(col => col.is_derived_column)
Expand Down
8 changes: 4 additions & 4 deletions seed/static/seed/js/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ SEED_app.config(['stateHelperProvider', '$urlRouterProvider', '$locationProvider
messages_payload: ['analyses_service', 'user_service', '$stateParams', function (analyses_service, user_service, $stateParams) {
return analyses_service.get_analysis_messages_for_org($stateParams.analysis_id, user_service.get_organization().id);
}],
organization_payload: ['user_service', function (user_service) {
return user_service.get_organization();
organization_payload: ['user_service', 'organization_service', function (user_service, organization_service) {
return organization_service.get_organization(user_service.get_organization().id);
}],
users_payload: ['organization_service', 'user_service', function (organization_service, user_service) {
return organization_service.get_organization_users({org_id: user_service.get_organization().id});
Expand Down Expand Up @@ -480,8 +480,8 @@ SEED_app.config(['stateHelperProvider', '$urlRouterProvider', '$locationProvider
view_payload: ['analyses_service', 'user_service', '$stateParams', function (analyses_service, user_service, $stateParams) {
return analyses_service.get_analysis_view_for_org($stateParams.analysis_id, $stateParams.run_id, user_service.get_organization().id);
}],
organization_payload: ['user_service', function (user_service) {
return user_service.get_organization();
organization_payload: ['user_service', 'organization_service', function (user_service, organization_service) {
return organization_service.get_organization(user_service.get_organization().id);
}],
users_payload: ['organization_service', 'user_service', function (organization_service, user_service) {
return organization_service.get_organization_users({org_id: user_service.get_organization().id});
Expand Down
15 changes: 15 additions & 0 deletions seed/static/seed/js/services/organization_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,20 @@ angular.module('BE.seed.service.organization', []).factory('organization_service
});
};

/**
* Returns the display value for an inventory
* @param {object} { property_display_field, taxlot_display_field }, organization object
* @param {string} inventory_type 'property' or 'taxlot'
* @param {object} inventory_state state object of the inventory
*/
organization_factory.get_inventory_display_value = function ({ property_display_field, taxlot_display_field }, inventory_type, inventory_state) {
const field = inventory_type === 'property' ? property_display_field : taxlot_display_field;
if (field == null) {
throw Error(`Provided display field for type "${inventory_type}" is undefined`);
}

return inventory_state[field];
}

return organization_factory;
}]);
4 changes: 2 additions & 2 deletions seed/static/seed/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@
"Property Detail": "Property Detail",
"Property Detail Notes": "Property Detail Notes",
"Property Detail Settings": "Property Detail Settings",
"Property Detail View Display Field": "Property Detail View Display Field",
"Property Display Field": "Property Display Field",
"Property Footprint": "Property Footprint",
"Property Name": "Property Name",
"Property Notes": "Property Notes",
Expand Down Expand Up @@ -776,7 +776,7 @@
"Tax Lot Visibility": "Tax Lot Visibility",
"Tax Lots": "Tax Lots",
"Tax Lots List": "Tax Lots List",
"Taxlot Detail View Display Field": "Taxlot Detail View Display Field",
"Taxlot Display Field": "Taxlot Display Field",
"Terms of Service": "Terms of Service",
"Terms of Service as of %(tos.created|date:\"SHORT_DATE_FORMAT\")s": "Terms of Service as of %(tos.created|date:\"SHORT_DATE_FORMAT\")s",
"Text": "Text",
Expand Down
4 changes: 2 additions & 2 deletions seed/static/seed/locales/fr_CA.json
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@
"Property Detail": "Détails de la propriété",
"Property Detail Notes": "Notes de détail de la propriété",
"Property Detail Settings": "Paramètres de détail de la propriété",
"Property Detail View Display Field": "Champ d'affichage de la vue détaillée de la propriété",
"Property Display Field": "Champ d'affichage de la propriété",
"Property Footprint": "Empreinte de propriété",
"Property Name": "Nom de la propriété",
"Property Notes": "Notes de propriété",
Expand Down Expand Up @@ -776,7 +776,7 @@
"Tax Lot Visibility": "Visibilité du lot d'impôt",
"Tax Lots": "Lots d'impôt",
"Tax Lots List": "Liste des lots d'impôt",
"Taxlot Detail View Display Field": "Champ d'affichage de la vue détaillée du lot de taxes",
"Taxlot Display Field": "Champ d'affichage du lot de taxes",
"Terms of Service": "Conditions d'utilisation",
"Terms of Service as of %(tos.created|date:\"SHORT_DATE_FORMAT\")s": "Conditions de service à partir de% (tos.created | date: \"SHORT_DATE_FORMAT\") s",
"Text": "Texte",
Expand Down
4 changes: 2 additions & 2 deletions seed/static/seed/partials/analysis_runs.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<td><a ui-sref="analysis_run(::{run_id: view.id, analysis_id: analysis.id, organization_id: org.id})" ui-sref-active="active">{$:: view.id $}</a></td>
<td>
<a ng-if="original_views[view.id]" ui-sref="inventory_detail({inventory_type: 'properties', view_id: original_views[view.id]})">
{$:: view.property_state.address_line_1 $} <i class="glyphicon glyphicon-log-out"></i>
{$:: get_display_name(view.property_state) || 'Property ' + original_views[view.id] $} <i class="glyphicon glyphicon-log-out"></i>
</a>
<span ng-if="!original_views[view.id]" uib-tooltip="Property no longer exists">
{$:: view.property_state.address_line_1 $}
{$:: get_display_name(view.property_state) || 'Unknown' $}
</span>
</td>
<td>
Expand Down
5 changes: 4 additions & 1 deletion seed/static/seed/partials/inventory_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ <h2>
<span ng-if="::inventory_type==='taxlots'">
<i class="fa fa-map-o"></i><span translate>Tax Lot</span> :
</span>
<span ng-bind-html="inventory_name">{$ inventory_display_name(inventory_type==='properties' ? 'property' : 'taxlot') | translate $}</span>
<span ng-style="!inventory_display_name && {'opacity': 0.5}">
{$ (inventory_display_name || 'Unknown') | translate $}
<i ng-if="!inventory_display_name" class="glyphicon glyphicon-question-sign" title="The display field can be changed from the organization settings page."></i>
</span>
</h2>
</span>
</div>
Expand Down
4 changes: 2 additions & 2 deletions seed/static/seed/partials/organization_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ <h3 translate>THERMAL_CONV_ASSUMPTION_TITLE</h3>
<uib-tab index="2" heading="{$:: 'Default Display Fields' | translate $}">
<div class="section_content_container">
<div class="section_content with_padding">
<h3 translate>Property Detail View Display Field</h3>
<h3 translate>Property Display Field</h3>
<small>Determines which column field is used when displaying and identifying a property. Defaults to "Address Line 1".</small>
<small>{$ all_columns $}</small>
<form class="form-horizontal" role="form">
Expand All @@ -187,7 +187,7 @@ <h3 translate>Property Detail View Display Field</h3>

<div class="section_content_container">
<div class="section_content with_padding">
<h3 translate>Taxlot Detail View Display Field</h3>
<h3 translate>Taxlot Display Field</h3>
<small>Determines which column field is used when displaying and identifying a taxlot. Defaults to "Address Line 1".</small>
<small>{$ all_columns $}</small>
<form class="form-horizontal" role="form">
Expand Down
2 changes: 2 additions & 0 deletions seed/static/seed/tests/inventory_detail_controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ describe('controller: inventory_detail_controller', function () {
organization: {
id: 1,
display_decimal_places: 2,
property_display_field: 'address_line_1',
taxlot_display_field: 'address_line_1',
},
},
analyses_payload: {
Expand Down
2 changes: 2 additions & 0 deletions seed/static/seed/tests/property_detail_controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ describe('controller: inventory_detail_controller', function () {
organization: {
id: 1,
display_decimal_places: 2,
property_display_field: 'address_line_1',
taxlot_display_field: 'address_line_1',
},
},
analyses_payload: {
Expand Down
2 changes: 2 additions & 0 deletions seed/static/seed/tests/taxlot_detail_controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ describe('controller: inventory_detail_controller', function () {
organization: {
id: 1,
display_decimal_places: 2,
property_display_field: 'address_line_1',
taxlot_display_field: 'address_line_1',
},
},
analyses_payload: {
Expand Down

0 comments on commit 4d16477

Please sign in to comment.