Skip to content

Commit d3f5065

Browse files
authored
revert: "adds equipment assets that have no parents" (#52)
Reverts #51 Forgot to commit the `fd2.sample.tar.gz` compressed database file.
1 parent abb720e commit d3f5065

File tree

2 files changed

+20
-61
lines changed

2 files changed

+20
-61
lines changed

src/sampleDB/addEquipment.js

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as farmosUtil from "../library/farmosUtil/farmosUtil.js";
33

44
import { basename, dirname } from "path";
55
import { fileURLToPath } from "url";
6-
import { LocalStorage } from "node-localstorage";
6+
import { LocalStorage } from 'node-localstorage';
77

88
/*
99
* Set the name of the CSV file to be processed and the
@@ -28,7 +28,7 @@ const pass = "admin";
2828
* Get a local storage object that we'll use to simulate the
2929
* browser's localStorage and sessionStorage when running in node.
3030
*/
31-
let ls = new LocalStorage("scratch");
31+
let ls = new LocalStorage('scratch');
3232

3333
/*
3434
* Get a fully initialized and logged in instance of the farmOS.js
@@ -61,55 +61,27 @@ let categoryName = null;
6161
*/
6262
async function processRow(row) {
6363
if (row[0] != "") {
64-
if (row.length == 1) {
65-
console.log(" Adding equipment " + row[0] + ", which has no parents...");
66-
const equipment = farm.asset.create({
67-
type: "asset--equipment",
68-
attributes: {
69-
name: row[0],
70-
},
71-
});
72-
} else if (row.length == 4) {
73-
console.log(" Adding equipment " + row[0] + ", which has no parents...");
74-
const equipment = farm.asset.create({
75-
type: "asset--equipment",
76-
attributes: {
77-
name: row[0],
78-
manufacturer: row[1],
79-
model: row[2],
80-
notes: row[3],
81-
},
82-
});
83-
} else {
84-
console.log(" Adding " + row[0] + "...");
85-
const equipment = farm.asset.create({
86-
type: "asset--equipment",
87-
attributes: {
88-
name: row[0],
89-
notes: row[1],
90-
},
91-
});
92-
categoryParentId = equipment.id;
93-
categoryParentName = row[0];
94-
}
64+
console.log(" Adding " + row[0] + "...");
65+
const categoryParent = farm.asset.create({
66+
type: "asset--equipment",
67+
attributes: {
68+
name: row[0],
69+
notes: row[1],
70+
},
71+
});
9572

9673
try {
97-
const result = await farm.asset.send(equipment);
74+
const result = await farm.asset.send(categoryParent);
75+
categoryParentId = result.id;
76+
categoryParentName = row[0];
9877
} catch (e) {
9978
console.log("API error sending " + row[0]);
10079
console.log(e);
10180
process.exit(1);
10281
}
10382
console.log(" Added.");
104-
10583
} else if (row[1] != "") {
106-
console.log(
107-
" Adding equipment category " +
108-
row[1] +
109-
" to category " +
110-
categoryParentName +
111-
"..."
112-
);
84+
console.log(" Adding equipment category " + row[1] + " to category " + categoryParentName + "...");
11385
const category = farm.asset.create({
11486
type: "asset--equipment",
11587
attributes: {

src/sampleDB/sampleData/equipment.csv

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
# Sample Data for the equipment assets
22
#
3-
# Each line represents either a category of equipment or
4-
# any equipment asset.
5-
#
63
# Format:
74
#
8-
# A left justified line creates an equipment asset with no parent
9-
# (e.g. Rake or Shovel) or it creates 'Category' which is the parent
10-
# of all categories of equipment
11-
#
12-
# A line beginning with a single comma:
13-
# Creates an equipment category with its parent being 'Category' that it
14-
# appears under.
15-
#
16-
# A line beginning with two commas:
17-
# Creates an equipment asset and sets its parent to the equipment
18-
# category that it appears under (i.e. General is the parent of Tractor)
5+
# Each line represents either a category of equipment or
6+
# any equipment asset.
197
#
208
# Equipment categories have the format:
219
# category name,category description.
2210
#
23-
# Equipment assets have the following comma delimited information:
24-
# name,manufacturer,model,description
11+
# Equipment within a category are listed immediately following its category
12+
# and have the following comma delimited information:
13+
# ,name,manufacturer,model,description
2514
#
2615
# Anything following a # on a line is a considered a comment.
2716
# Thus, names and descriptions cannot contain #
2817
# Blank Lines are ignored.
2918

30-
Rake,Company A,9871,A garden rake.
31-
Shovel,
32-
Category,Parent of all categories
19+
Category, Parent of all categories
3320
,General,Equipment used for a variety of operations.
3421
,,Tractor,Company G,468,A standard tractor.
3522
,,Small Tractor,Company I,987,A compact tractor.

0 commit comments

Comments
 (0)