The MORGANA model for the rise of galaxies and active nuclei