Skip to content

Commit

Permalink
functional with audit log issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Perry authored and Ross Perry committed Dec 19, 2024
1 parent d063dd9 commit 48d1019
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 125 deletions.
85 changes: 47 additions & 38 deletions seed/static/seed/js/controllers/inventory_create_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ angular.module('SEED.controller.inventory_create', []).controller('inventory_cre
'all_columns',
'cycles',
'profiles',
'organization_payload',
// eslint-disable-next-line func-names
function (
$scope,
Expand All @@ -24,9 +23,8 @@ angular.module('SEED.controller.inventory_create', []).controller('inventory_cre
all_columns,
cycles,
profiles,
organization_payload,
) {
$scope.inventory = {};
$scope.data = { state: { extra_data: {} } };
$scope.inventory_type = $stateParams.inventory_type;
$scope.inventory_types = ['Property', 'TaxLot'];
const table_name = $scope.inventory_type === 'taxlots' ? 'TaxLotState' : 'PropertyState';
Expand All @@ -45,15 +43,15 @@ angular.module('SEED.controller.inventory_create', []).controller('inventory_cre
if (!c.is_extra_data && !c.derived_column) $scope.canonical_columns.push(c);
}
});
// create a copy, not a reference
$scope.inventory.form_columns =[...$scope.matching_columns];
// create a copy, not a reference. from_column contents is a list of columns dicts
$scope.form_columns =[...$scope.matching_columns];
// form_values allows value persistance
$scope.form_values = [];

$scope.remove_column = (index) => {
$scope.inventory.form_columns.splice(index, 1)
$scope.form_values[index] = null;
};
$scope.add_column = () => $scope.inventory.form_columns.push({displayName: '', table_name: table_name});
$scope.$watch('data', () => {
console.log('watch')
$scope.valid = $scope.data.cycle && $scope.data.access_level_instance && !_.isEqual($scope.data.state, { extra_data: {} });
}, true)


// ACCESS LEVEL TREE
Expand All @@ -64,49 +62,56 @@ angular.module('SEED.controller.inventory_create', []).controller('inventory_cre
}));
const access_level_instances_by_depth = ah_service.calculate_access_level_instances_by_depth($scope.access_level_tree);
$scope.change_selected_level_index = () => {
const new_level_instance_depth = parseInt($scope.inventory.level_name_index, 10) + 1;
const new_level_instance_depth = parseInt($scope.data.level_name_index, 10) + 1;
$scope.potential_level_instances = access_level_instances_by_depth[new_level_instance_depth];
};
$scope.inventory.level_name_index = $scope.level_names.at(-1).index;
$scope.data.level_name_index = $scope.level_names.at(-1).index;
$scope.change_selected_level_index();
$scope.inventory.access_level_instance = $scope.potential_level_instances.at(0).id;
$scope.data.access_level_instance = $scope.potential_level_instances.at(0).id;

// COLUMN LIST PROFILES
$scope.set_columns = (type) => {
remove_empty_last_column();
switch (type) {
case 'canonical':
$scope.inventory.form_columns = Array.from(new Set([...$scope.inventory.form_columns, ...$scope.canonical_columns]));
$scope.form_columns = Array.from(new Set([...$scope.form_columns, ...$scope.canonical_columns]));
break;
case 'extra':
$scope.inventory.form_columns = Array.from(new Set([...$scope.inventory.form_columns, ...$scope.extra_columns]));
$scope.form_columns = Array.from(new Set([...$scope.form_columns, ...$scope.extra_columns]));
break;
default:
$scope.inventory.form_columns = [...$scope.matching_columns];
$scope.inventory.form_columns = $scope.inventory.form_columns.map(c => ({...c, value: null}));
$scope.form_columns = [...$scope.matching_columns];
$scope.form_columns = $scope.form_columns.map(c => ({...c, value: null}));
$scope.form_values = [];
}
}

// FORM LOGIC
$scope.remove_column = (column, index) => {
$scope.form_columns.splice(index, 1)
$scope.form_values[index] = null;
set_column_value(column, null);
};

$scope.add_column = () => $scope.form_columns.push({ displayName: '', table_name: table_name });

const remove_empty_last_column = () => {
if (!_.isEmpty($scope.inventory.form_columns) && $scope.inventory.form_columns.at(-1).displayName === '') {
$scope.inventory.form_columns.pop();
if (!_.isEmpty($scope.form_columns) && $scope.form_columns.at(-1).displayName === '') {
$scope.form_columns.pop();
}
}


// FORM LOGIC
$scope.change_profile = () => {
const profile_column_names = $scope.profile.columns.map(p => p.column_name);
$scope.inventory.form_columns = $scope.columns.filter(c => profile_column_names.includes(c.column_name))
$scope.form_columns = $scope.columns.filter(c => profile_column_names.includes(c.column_name))
}

$scope.select_column = (column, idx) => {
column.value = $scope.form_values.at(idx);
$scope.inventory.form_columns[idx] = column;
$scope.select_column = (column, index) => {
column.value = $scope.form_values.at(index);
$scope.form_columns[index] = column;
}

$scope.change_column = (displayName, idx) => {
$scope.change_column = (displayName, index) => {
const defaults = {
table_name: table_name,
is_extra_data: true,
Expand All @@ -116,24 +121,28 @@ angular.module('SEED.controller.inventory_create', []).controller('inventory_cre
let column = $scope.columns.find(c => c.displayName === displayName) || {displayName: displayName};
column = {...defaults, ...column};

column.value = $scope.form_values.at(idx);
$scope.inventory.form_columns[idx] = column;
column.value = $scope.form_values.at(index);
$scope.form_columns[index] = column;
};

$scope.change_value = (value, idx) => {
$scope.form_values[idx] = value;
$scope.change_value = (column, index) => {
$scope.form_values[index] = column.value;
set_column_value(column, column.value)
}

$scope.save_inventory = () => {
console.log('save_inventory', $scope.inventory)
const set_column_value = (column, value) => {
const column_name = column.column_name || column.displayName;
if (!column_name) return
const target = column.is_extra_data ? $scope.data.state.extra_data : $scope.data.state;
target[column_name] = value;
}







$scope.save_inventory = () => {
console.log($scope.data.state)
inventory_service.create_inventory($scope.data, $scope.inventory_type).then((data) => {
console.log('>>>', data)
})
}

}
]);
1 change: 0 additions & 1 deletion seed/static/seed/js/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2276,7 +2276,6 @@
return inventory_service.get_column_list_profiles('List View Profile', inventory_type);
}
],
organization_payload: ['user_service', 'organization_service', (user_service, organization_service) => organization_service.get_organization(user_service.get_organization().id)]
}
})
.state({
Expand Down
30 changes: 10 additions & 20 deletions seed/static/seed/partials/inventory_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,16 @@

<div class="page_header_container" ng-cloak>
<div class="page_header">
<div class="left page_action_container">
<a ng-show="group_id != null" ui-sref="inventory_groups(::{inventory_type: inventory_type})"
class="page_action">
<i class="fa-solid fa-chevron-left"></i>
{$:: 'Groups' | translate $}
</a>
</div>
<div class="left page_action_container"></div>
<div class="page_title">
<h1>{$:: (group_id? 'Group - ': '')$}{$:: (inventory_type === 'taxlots' ? 'Tax Lots' : 'Properties') |
translate $}</h1>
<h1>{$:: (inventory_type === 'taxlots' ? 'Tax Lots' : 'Properties') | translate $}</h1>
</div>
<div class="right page_action_container"></div>
</div>
</div>

<div class="section_nav_container">
<div ng-show="group_id == null" class="section_nav"
ng-include="::urls.static_url + 'seed/partials/inventory_nav.html'"></div>
<div ng-show="group_id != null" class="section_nav"
ng-include="::urls.static_url + 'seed/partials/inventory_group_detail_nav.html'"></div>
<div class="section_nav" ng-include="::urls.static_url + 'seed/partials/inventory_nav.html'"></div>
</div>

<div class="section_header_container">
Expand All @@ -34,7 +24,7 @@ <h1>{$:: (group_id? 'Group - ': '')$}{$:: (inventory_type === 'taxlots' ? 'Tax L
<h2><i class="fa-regular fa-building"></i><span>Create a {$ inventory_type === 'properties' ? 'Property' : 'Tax Lot'$}</span></h2>
</div>
<div class="section_action_container right_40 section_action_btn pull-right">
<button class="btn btn-primary" ng-click="save_inventory()">Save {$ inventory_type == 'taxlots' ? 'TaxLot' : 'Property' $}</button>
<button class="btn btn-primary" ng-disabled="!valid" ng-click="save_inventory()">Save {$ inventory_type == 'taxlots' ? 'TaxLot' : 'Property' $}</button>
</div>
</div>
</div>
Expand All @@ -46,21 +36,21 @@ <h2><i class="fa-regular fa-building"></i><span>Create a {$ inventory_type === '
<label for="select-level-name" translate>Access Level</label>
<select id="select-level-name" class="form-control "
ng-options="level.index as level.name for level in level_names" ng-change="change_selected_level_index()"
ng-model="inventory.level_name_index" required></select>
ng-model="data.level_name_index"></select>
</div>
<div class="col-sm-4">
<label for="select-level-instance" translate>Level Instance</label>
<select id="select-level-instance" class="form-control" ng-change=""
ng-options="potential_level_instance.id as potential_level_instance.name for potential_level_instance in potential_level_instances"
ng-model="inventory.access_level_instance" required></select>
ng-model="data.access_level_instance"></select>
</div>
</div>
<div class="content-row">
<div class="col-sm-4">
<label for="cycle" translate>Cycle</label>
<select id="select-cycle" class="form-control" ng-change=""
ng-options="cycle.id as cycle.name for cycle in cycles"
ng-model="inventory.cycle" required></select>
ng-model="data.cycle"></select>
</div>
</div>
<div class="content-row">
Expand Down Expand Up @@ -91,7 +81,7 @@ <h2><i class="fa-regular fa-building"></i><span>Create a {$ inventory_type === '
</tr>
</thead>
<tbody>
<tr ng-repeat="column in inventory.form_columns track by $index">
<tr ng-repeat="column in form_columns track by $index">
<td>{$ column.table_name.slice(0, -5) $}</td>
<!-- <td style="max-width:200px;">{$ column.displayName $}</td> -->
<td ng-attr-id="row-input-{$:: $index $}">
Expand All @@ -116,13 +106,13 @@ <h2><i class="fa-regular fa-building"></i><span>Create a {$ inventory_type === '
aria-label="New column name" />
</td>
<td>
<input type="text" class="form-control" ng-model="column.value" ng-change="change_value(column.value, $index)" />
<input type="text" class="form-control" ng-model="column.value" ng-change="change_value(column, $index)" />
</td>
<td>{$ column.is_matching_criteria $}</td>
<td>{$ column.is_extra_data $}</td>
<td style="width: 100px;" >{$ column.data_type $}</td>
<td>
<button class="btn btn-danger" type="button" ng-click="remove_column($index)">
<button class="btn btn-danger" type="button" ng-click="remove_column($index, column)">
<i class="fa-solid fa-xmark"></i>
</button>
</td>
Expand Down
43 changes: 22 additions & 21 deletions seed/tests/test_property_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,45 +665,46 @@ def test_property_form_create(self):
original_property_count = Property.objects.count()

url = reverse("api:v3:properties-form-create") + f"?organization_id={self.org.pk}"
pm_property_id = Column.objects.get(column_name="pm_property_id", organization=self.org)
pm_property_id = ColumnSerializer(pm_property_id).data
custom_id_1 = Column.objects.get(column_name="custom_id_1", table_name="PropertyState", organization=self.org)
custom_id_1 = ColumnSerializer(custom_id_1).data
extra = {"displayName": "Extra Data Column", "value": "XYZ"}

state_data = {
"pm_property_id": "123",
"custom_id_1": "ABC",
"extra_data": {"Extra Data Column": "456"},
}

data = {
"access_level_instance": self.org.root.id,
"cycle": self.cycle.id,
"form_columns": [
{**pm_property_id, "value": "123"},
{**custom_id_1, "value": "ABC"},
extra
]
"state": state_data
}

self.client.post(url, json.dumps(data), content_type="application/json")
# For a new property, counts should only increase by 1
assert PropertyState.objects.count() == original_state_count + 1
assert PropertyView.objects.count() == original_view_count + 1
assert Property.objects.count() == original_property_count + 1

# # verify with existing matches

# verify with existing matches
cycle2 = self.cycle_factory.get_cycle(start=datetime(2000, 10, 10, tzinfo=get_current_timezone()))
cycle3 = self.cycle_factory.get_cycle(start=datetime(2020, 10, 10, tzinfo=get_current_timezone()))
view = self.property_view_factory.get_property_view(cycle=cycle2, pm_property_id="456", custom_id_1="DEF")
self.property_view_factory.get_property_view(cycle=cycle2, pm_property_id="456", custom_id_1="DEF")

state_data = {
"pm_property_id": "456",
"custom_id_1": "DEF",
"extra_data": {"Extra Data Column": "GHI"},
}
data = {
"access_level_instance": self.org.root.id,
"cycle": self.cycle.id,
"form_columns": [
{**pm_property_id, "value": "456"},
{**custom_id_1, "value": "DEF"},
{"displayName": "Column2", "value": "GHI"}
]
"state": state_data
}

self.client.post(url, json.dumps(data), content_type="application/json")


assert True
# For property merges, counts should increase by 2 (new property, and merged property)
assert PropertyState.objects.count() == original_state_count + 3
assert PropertyView.objects.count() == original_view_count + 3
assert Property.objects.count() == original_property_count + 3


class PropertyViewTestsPermissions(AccessLevelBaseTestCase):
Expand Down
Loading

0 comments on commit 48d1019

Please sign in to comment.