diff --git a/app/common/publishEnums.js b/app/common/publishEnums.js
index 85988d5..fd481fb 100644
--- a/app/common/publishEnums.js
+++ b/app/common/publishEnums.js
@@ -50,7 +50,7 @@ const BASIC_BOOLEAN_PUBLISH = [
}
];
-const BASIC_INPUT_PUBLISH_NO = [
+const BASIC_INPUT_PUBLISH = [
{
dbField: "price",
title: "Cijena (KM)",
@@ -111,10 +111,7 @@ const BASIC_INPUT_PUBLISH_NO = [
AD_CATEGORY.APARTMENT,
AD_CATEGORY.OFFICE
]
- }
-];
-
-const BASIC_INPUT_PUBLISH = [
+ },
{
dbField: "title",
title: "Naslov",
@@ -477,7 +474,6 @@ const ADDITIONAL_SEGMENT_PUBLISH = [
module.exports = {
BASIC_INPUT_PUBLISH,
- BASIC_INPUT_PUBLISH_NO,
BASIC_SEGMENT_PUBLISH,
BASIC_BOOLEAN_PUBLISH,
ADDITIONAL_BOOLEAN_PUBLISH,
diff --git a/app/controllers/publishRealEstate.js b/app/controllers/publishRealEstate.js
index 90cf359..baaf755 100644
--- a/app/controllers/publishRealEstate.js
+++ b/app/controllers/publishRealEstate.js
@@ -3,6 +3,13 @@ const { createRealEstate } = require("../helpers/db/realEstate");
const { createKiviOriginal } = require("../helpers/db/kiviOriginal");
const { AD_CATEGORY, AD_TYPE, AD_AGENCY } = require("../common/enums");
+const {
+ BASIC_BOOLEAN_PUBLISH,
+ BASIC_SEGMENT_PUBLISH,
+ ADDITIONAL_BOOLEAN_PUBLISH,
+ ADDITIONAL_SEGMENT_PUBLISH,
+ BASIC_INPUT_PUBLISH
+} = require("../common/publishEnums");
const getPublishInputs = async (req, res) => {
const realEstate = await currentRealEstate(req);
@@ -14,8 +21,133 @@ const getPublishInputs = async (req, res) => {
const title = "Podaci o nekretnini";
+ const {
+ price,
+ area,
+ adType,
+ realEstateType,
+ locationLat,
+ locationLong,
+ accessRoadType,
+ heatingType,
+ balcony,
+ newBuilding,
+ elevator,
+ recentlyAdapted,
+ gardenSize,
+ numberOfRooms,
+ numberOfFloors,
+ floor,
+ water,
+ electricity,
+ drainageSystem,
+ registeredInZkBooks,
+ parking,
+ garage,
+ gas,
+ antiTheftDoor,
+ airCondition,
+ phoneConnection,
+ cableTV,
+ internet,
+ basementAttic,
+ storeRoom,
+ videoSurveillance,
+ alarm,
+ suitableForStudents,
+ includingBills,
+ animalsAllowed,
+ pool,
+ exchange,
+ urbanPlanPermit,
+ buildingPermit,
+ furnishingType,
+ shortDescription,
+ streetName
+ } = realEstate;
+ const category = AD_CATEGORY[realEstateType] || AD_CATEGORY.FLAT;
+
+ // TODO: Maybe this is slow, pay attention to this
+ const filterInputs = filterObject => {
+ const filterCategories = filterObject.categoriesToShow;
+ return filterCategories.indexOf(category) !== -1;
+ };
+ //Boolean inputs to be shown on Basic Data tab
+ const basicBooleanPublishInputs = BASIC_BOOLEAN_PUBLISH.filter(filterInputs);
+ const basicBooleanPublishValues = {
+ balcony,
+ elevator,
+ newBuilding,
+ recentlyAdapted
+ };
+ //Boolean inputs to be shown on Additional Data tab
+ const additionalBooleanPublishInputs = ADDITIONAL_BOOLEAN_PUBLISH.filter(
+ filterInputs
+ );
+ const additionalBooleanPublishValues = {
+ water,
+ electricity,
+ drainageSystem,
+ registeredInZkBooks,
+ parking,
+ garage,
+ gas,
+ antiTheftDoor,
+ airCondition,
+ phoneConnection,
+ cableTV,
+ internet,
+ basementAttic,
+ storeRoom,
+ videoSurveillance,
+ alarm,
+ suitableForStudents,
+ includingBills,
+ animalsAllowed,
+ pool,
+ exchange,
+ urbanPlanPermit,
+ buildingPermit
+ };
+ //Segment select inputs to be shown on Basic Data tab
+ const basicSegmentSelectInputs = BASIC_SEGMENT_PUBLISH.filter(filterInputs);
+ const basicSegmentSelectValues = {
+ furnishingType
+ };
+ //Segment select inputs to be shown on Additional Data tab
+ const additionalSegmentSelectInputs = ADDITIONAL_SEGMENT_PUBLISH.filter(
+ filterInputs
+ );
+ const additionalSegmentSelectValues = {
+ accessRoadType,
+ heatingType
+ };
+ //Input text type inputs to be shown on Basic Data tab
+ const basicInputInputs = BASIC_INPUT_PUBLISH.filter(filterInputs);
+ const basicInputValues = {
+ price,
+ area,
+ gardenSize,
+ numberOfRooms,
+ numberOfFloors,
+ floor,
+ title,
+ shortDescription,
+ streetName
+ };
+
res.render("publishRealEstate", {
- title
+ title,
+ basicBooleanPublishInputs,
+ basicBooleanPublishValues,
+ additionalBooleanPublishInputs,
+ additionalBooleanPublishValues,
+ basicSegmentSelectInputs,
+ basicSegmentSelectValues,
+ additionalSegmentSelectInputs,
+ additionalSegmentSelectValues,
+ basicInputInputs,
+ basicInputValues
});
};
@@ -26,6 +158,85 @@ const postPublishInputs = async (req, res) => {
res.render("notFound", { title: " " });
return;
}
+
+ const balcony = req.body.balcony === "on";
+ const elevator = req.body.elevator === "on";
+ const newBuilding = req.body.newBuilding === "on";
+ const recentlyAdapted = req.body.recentlyAdapted === "on";
+ const water = req.body.water === "on";
+ const electricity = req.body.electricity === "on";
+ const drainageSystem = req.body.drainageSystem === "on";
+ const registeredInZkBooks = req.body.registeredInZkBooks === "on";
+ const parking = req.body.parking === "on";
+ const garage = req.body.garage === "on";
+ const gas = req.body.gas === "on";
+ const antiTheftDoor = req.body.antiTheftDoor === "on";
+ const airCondition = req.body.airCondition === "on";
+ const phoneConnection = req.body.phoneConnection === "on";
+ const cableTV = req.body.cableTV === "on";
+ const internet = req.body.internet === "on";
+ const basementAttic = req.body.basementAttic === "on";
+ const storeRoom = req.body.storeRoom === "on";
+ const videoSurveillance = req.body.videoSurveillance === "on";
+ const alarm = req.body.alarm === "on";
+ const suitableForStudents = req.body.suitableForStudents === "on";
+ const includingBills = req.body.includingBills === "on";
+ const animalsAllowed = req.body.animalsAllowed === "on";
+ const pool = req.body.pool === "on";
+ const exchange = req.body.exchange === "on";
+ const urbanPlanPermit = req.body.urbanPlanPermit === "on";
+ const buildingPermit = req.body.buildingPermit === "on";
+
+ const furnishingType = req.body.furnishingType;
+ if (!FURNISHING_TYPE[furnishingType]) {
+ res.render("notFound", { title: " Greška !" });
+ return;
+ }
+ const accessRoadType = req.body.accessRoadType;
+ if (!ACCESS_ROAD_TYPE[accessRoadType]) {
+ res.render("notFound", { title: " Greška !" });
+ return;
+ }
+ const heatingType = req.body.heatingType;
+ if (!HEATING_TYPE[heatingType]) {
+ res.render("notFound", { title: " Greška !" });
+ return;
+ }
+
+ realEstate.balcony = balcony;
+ realEstate.elevator = elevator;
+ realEstate.newBuilding = newBuilding;
+ realEstate.recentlyAdapted = recentlyAdapted;
+ realEstate.water = water;
+ realEstate.electricity = electricity;
+ realEstate.drainageSystem = drainageSystem;
+ realEstate.registeredInZkBooks = registeredInZkBooks;
+ realEstate.parking = parking;
+ realEstate.garage = garage;
+ realEstate.gas = gas;
+ realEstate.antiTheftDoor = antiTheftDoor;
+ realEstate.airCondition = airCondition;
+ realEstate.phoneConnection = phoneConnection;
+ realEstate.cableTV = cableTV;
+ realEstate.internet = internet;
+ realEstate.basementAttic = basementAttic;
+ realEstate.storeRoom = storeRoom;
+ realEstate.videoSurveillance = videoSurveillance;
+ realEstate.alarm = alarm;
+ realEstate.suitableForStudents = suitableForStudents;
+ realEstate.includingBills = includingBills;
+ realEstate.animalsAllowed = animalsAllowed;
+ realEstate.pool = pool;
+ realEstate.exchange = exchange;
+ realEstate.urbanPlanPermit = urbanPlanPermit;
+ realEstate.buildingPermit = buildingPermit;
+
+ realEstate.furnishingType = furnishingType;
+ realEstate.accessRoadType = accessRoadType;
+ realEstate.heatingType = heatingType;
+ //
+ console.log("postPublishInputs");
+ await realEstate.save();
};
module.exports = {
diff --git a/app/views/publishAdditionalData.ejs b/app/views/publishAdditionalData.ejs
index b7b7b73..39c7084 100644
--- a/app/views/publishAdditionalData.ejs
+++ b/app/views/publishAdditionalData.ejs
@@ -1 +1,31 @@
-Publish Additional Data
\ No newline at end of file
+
+
+<% for (const input of additionalBooleanPublishInputs){ %>
+
+ +
+<% } %> + ++ +
+<% } %> +